question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] null returned for 204

See original GitHub issue

Hi,

we’re running Python 3.7.3 with FastAPI 0.27.2 and have the following API definition (simplified):

app.post("/url", status_code = HTTP_204_OK)
async def set_data(data: Data) -> None: 
   await db.set_data(data)

We return a 204 and return nothing in the body but we see that null is returned with a content length of 4. The client expect content-length = 0 for a 204 response. Can this please be fixed?

Thanks, Daniel

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
dmontagucommented, Aug 21, 2019

To add to @euri10 's point, you can similarly fix this via:

from starlette.responses import Response

@app.post("/url", status_code = HTTP_204_OK, response_class=Response)
async def set_data(data: Data) -> None: 
   await db.set_data(data)
5reactions
euri10commented, Aug 21, 2019

Still baffled about the null return, but workaround works so I’ll close the ticket.

Thanks

I agree, maybe worth a ping upstream as the current API let you return a 204 with content, which shouldn’t be possible

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Null response returns a 204
"HTTP 204 NO CONTENT: The server has successfully fulfilled the request and that there is no additional content to send in the response...
Read more >
Null API Responses and HTTP 204 Results in ASP.NET Core
ASP.NET Core 3.x has a behavior that results in API results that return null from the controller action returning a HTTP 204 -...
Read more >
Unable to construct a null body Response with status 204
The spec says Response should have null body if its first argument is not given, which means undefined is given.
Read more >
#43691 (class-wp-rest-server sends response body ...
Status code 204 should indicate no response body is sent. Previously, a "null" string was sent, which MacOS Safari would try to parse...
Read more >
Bug ID: JDK-8211420 com.sun.net.httpserver. ...
HttpServer returns Content-length header for 204 response code ... setExecutor(null); server.start(); } static class MyHandler implements HttpHandler ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found