Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that Response.iter_lines is broken and should be avoided #6570

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bemoody
Copy link

@bemoody bemoody commented Nov 10, 2023

The Response.iter_lines method is seriously broken (it inserts fake blank lines in unpredictable places.)

The earliest report of this I've found is pull #2431 (January 2015).

The behavior was apparently fixed in the 3.0.0 branch, by pulls #3923 and #3984. (I think #3923 fixes the delimiter!=None case and #3984 fixes the delimiter=None case. But I haven't tested it.)

The problem was raised again in issues #3980, #4121, and #5540.

Pull #4629 attempted to partially fix the issue in the master branch, and was rejected.

Personally, I am skeptical that there is any benefit in preserving this broken behavior. But folks who know better than I do have said that it needs to be maintained.

As long as this isn't fixed, people using the library should be informed that method is broken and they shouldn't use it.

This method is broken in a couple of significant ways:

- If delimiter is None, and if one chunk happens to end with \r and
  the following chunk begins with \n, this method will yield a bogus
  blank line at that point.

- If delimiter is a string, and if a chunk happens to end with that
  string, this method will yield a bogus blank line at that point.

This is broken both with and without decode_unicode=True, and it is
broken both with and without stream=True.  (Setting stream=True makes
the problem worse, because then the chunk boundaries are partially
dependent on server or network I/O chunking.)

Unless and until this behavior is fixed, this method should not be
used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant