swagger-api / swagger-api/swagger-codegen

[Python] tornado client does not support chunked responses

Open
#7,745 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The python tornado client does not support chunked/streaming responses. When _preload_content is True the entire response body is read. When _preload_content is False the response body is still read but the raw tornado request is returned instead (probably a bug).

I think the expected behavior should be similar to using urllib3: When _preload_content=True the response body should not be be read, allowing the caller to call read_chunk on the response object, and presumably handle the deserialization of the chunks themselves.

Suggest a fix/enhancement

Unfortunately, for tornado to support reading streaming responses you must provide a streaming_callback to the request which is called whenever a chunk arrives off the socket. There is no other way way to prevent the client from attempting to read the entire response body. Allowing the caller to specify a callback doesn't really mesh well with the way the APIClient works, so it likely requires some trickery to make it work (and a bit of buffering).

FWIW, the python asyncio client probably has a similar issue where the response body is always read, though the fix is probably simpler since aiohttp doesn't require a callback, but I've not looked into this much.

I have a PR for this in progress.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python Tornado client and APIClient handling of _preload_content, comparing the behavior described with urllib3 and the asyncio client. Trace how Tornado requests consume response bodies and how a streaming callback could be buffered. Done means chunked responses can be consumed incrementally without forcing the full body read, while preserving the expected deserialization behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.