You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Where we POST to as a notification
@live_server.app.route('/test_notification_endpoint', methods=['POST', 'GET'])
def test_notification_endpoint():
p = request.headers
but request.headers is always empty (by empty i mean contains \r\n), downgrading to 3.0.6 fixed it (from 3.1.0)
Tried python 3.10, 3.11, and 3.12
pytest 7.4.4
pytest-flask 1.3.0
Werkzeug 3.0.6 (this version is OK)
Strangely, all other variables in request look perfectly OK, tcpdump shows the headers are being sent without problem, HTTP_ type vars in the request look OK too
thanks!
Reacted by leofdgit, haider, dgtlmoon and Magnus Lyckå
Header code was refactored a bit when moving the type annotations in, but all tests continue to pass in both Werkzeug and Flask. If you can create a minimal reproducible example, I do want to trace what's happening.
I think I might have a reproducible example, if I return str(request.headers), Headers.__str__ seems to be returning an empty string, so something happened. I might know what happened, I'll step through with a debugger for a bit.
Aha, I was too clever. Headers stores a list of headers internally, and I thought I'd save some function calls/iterator setup by iterating over that list directly in __str__. EnvironHeaders (what request.headers is) subclasses Headers but ignores the internal list and uses the environ dict instead. So my refactor accidentally made it always look at the empty internal list instead of calling __iter__. I'll fix that and have 3.1.1 soon.
Reacted by dgtlmoon and Mischan Toosarani-Hausberger
@magnus-lycka It doesn't sound like that's related to this. Can you please report a separate bug with a minimal reproducible example?
I think it's the same issue. If headers are gone, I assume our auth won't work. This is a pretty big old monolith, and I'm definitely not able to create something reproducible this week. It's 16:46 Friday... I just noticed that 93 unit tests suddenly failed, with assertion for all sorts of values of status suddenly all being 401. Not sure how that works. Pinning to 3.0.6. for now, and will let you know if a fix for this missing headers problem fixes my problem or not.
@magnus-lycka I understand now, yeah if you're sending custom auth headers maybe this is related. Headers aren't gone though, only str(request.headers) was affected. I'm about to release 3.1.1 then, open a new issue if it persists after that. I tried to play around with test_client() really quick, but Flask and Werkzeug's tests with it all still pass before this fix.
Activity
candh commentedon Nov 1, 2024
for anyone passing by: this also messes up
reqparseofflask_restfuldavidism commentedon Nov 1, 2024
I can't reproduce this issue with the information provided. The following echoes back all headers sent by the browser:
Header code was refactored a bit when moving the type annotations in, but all tests continue to pass in both Werkzeug and Flask. If you can create a minimal reproducible example, I do want to trace what's happening.
dgtlmoon commentedon Nov 1, 2024
Hmm as a stand alone flask application I can also not reproduce it, but I can reproduce it in my pytest endpoint
davidism commentedon Nov 1, 2024
I think I might have a reproducible example, if I return
str(request.headers),Headers.__str__seems to be returning an empty string, so something happened. I might know what happened, I'll step through with a debugger for a bit.davidism commentedon Nov 1, 2024
Aha, I was too clever.
Headersstores a list of headers internally, and I thought I'd save some function calls/iterator setup by iterating over that list directly in__str__.EnvironHeaders(whatrequest.headersis) subclassesHeadersbut ignores the internal list and uses theenvirondict instead. So my refactor accidentally made it always look at the empty internal list instead of calling__iter__. I'll fix that and have 3.1.1 soon.magnus-lycka commentedon Nov 1, 2024
davidism commentedon Nov 1, 2024
[-]pytest/flask test endpoint loses headers in `3.1.0` was OK in `3.0.6`[/-][+]`str(request.headers)` is empty[/+]magnus-lycka commentedon Nov 1, 2024
I think it's the same issue. If headers are gone, I assume our auth won't work. This is a pretty big old monolith, and I'm definitely not able to create something reproducible this week. It's 16:46 Friday... I just noticed that 93 unit tests suddenly failed, with assertion for all sorts of values of status suddenly all being 401. Not sure how that works. Pinning to 3.0.6. for now, and will let you know if a fix for this missing headers problem fixes my problem or not.
davidism commentedon Nov 1, 2024
@magnus-lycka I understand now, yeah if you're sending custom auth headers maybe this is related. Headers aren't gone though, only
str(request.headers)was affected. I'm about to release 3.1.1 then, open a new issue if it persists after that. I tried to play around withtest_client()really quick, but Flask and Werkzeug's tests with it all still pass before this fix.dgtlmoon commentedon Nov 1, 2024
thank you so much!
magnus-lycka commentedon Nov 4, 2024
Turns out my optimism was unfounded. My issue remains with 3.1.1. Sigh... I'll try to distill my issue and file a new issue.