Non-string anchors no longer work
Forty-Bot opened this issue · 4 comments
Passing non-string values to url_for
no longer works. For example,
url_for('my_endpoint', _anchor=5)
It now fails with TypeError: quote_from_bytes() expected bytes
.
Werkzeug is deprecating and removing bytes support, so this would be fixed there if necessary. But it was never intended to accept non-strings, that was just a side effect of the extra checks that were required to support bytes. I don't really see the value in changing this back.
But it was never intended to accept non-strings, that was just a side effect of the extra checks that were required to support bytes
The effect was that you could pass non-strings to this function and they would be converted automatically. Many other parameters to this function work this way. For example, if you have an int
parameter on your endpoint, it will be converted to str
automatically.
The intention doesn't really matter. This is a regression in behavior.
Where was the deprecation period? You should also have something in the release notes about changing the behavior...
https://flask.palletsprojects.com/en/2.3.x/changes/#version-2-3-0
Update minimum requirements to the latest versions: Werkzeug>=2.3.0
https://werkzeug.palletsprojects.com/en/2.3.x/changes/#version-2-3-0
Deprecate the
werkzeug.urls
module, except for theuri_to_iri
andiri_to_uri
functions. Use theurllib.parse
library instead.
Passing bytes where strings are expected is deprecated ... Anywhere that was annotated, documented, or tested to accept bytes shows a warning.
Passing a non-string as an anchor was never intentionally supported, you were relying on undefined behavior. I don't plan to add a warning back in just to then remove it again. It's the same result either way here: you need to pass a string.