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

Fix #1142: address deprecation of werkzeug.urls.url_parse #1143

Merged
merged 6 commits into from May 5, 2023

Conversation

dairiki
Copy link
Contributor

@dairiki dairiki commented May 3, 2023

Issue(s) Resolved

Fixes #1142

Related Issues / Links

Documentation updates for this PR are in lektor/lektor-website#371

Description of Changes

This PR disuses werkzeug.urls.url_parse in favor of the equivalents from stdlib's urllib.parse, thus avoiding deprecation warnings from werkzeug>=2.3.0, and (hopefully) ensuring compatibility with werkzeug 2.4.

Breaking Change of Publisher API

Currently, (before this PR) the target_url parameter of the Publisher.publish method was expected to be a werkzeug.urls.URL instance. Since werkzeug.urls.URL is going away, that is obviously not sustainable. In this PR we change to passing a str for target_url.

Doing this the simple way, however, would break existing external plugins (e.g. lektor-algolia, lektor-gae, lektor-s3, lektor-netlify, lektor-git-src-publisher, lektor-quiniu, lektor-surge) that implement custom publishers.
To prevent such breakage, in this PR we pass a custom subclass of str that implements (most of) the attributes and methods of werkzeug.urls.URL (but issues a deprecation warning when they are accessed.)

Breaking Changelet — Url.query

Instances of lektor.utils.Url are what is exposed to jinja templates for Lektor record fields of type "url".

This PR changes the semantics of lektor.utils.Url.query from returning the URI-encoded (ASCII) query to returning the IRI-encoded (internationalize, unicode) version of the query. The other similar attributes of Url (e.g. Url.host, Url.path, Url.anchor) all already returned the IRI versions, so I'm not sure why .query was being treated differently.

Deprecation — Pad.make_absolute_url

This PR deprecates lektor.db.Pad.make_absolute_url. We have not used it since 93de7d9, and, anyway, lektor.db.Pad.make_url provides equivalent functionality.

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Link to corresponding documentation pull request for getlektor.com

The rest of the attributes of Url (e.g. host, path, anchor) all return
the IRI (internationalized) version of their values.  I'm not sure why
query is different.
@dairiki dairiki marked this pull request as draft May 3, 2023 01:26
@dairiki dairiki force-pushed the fix.werkzeug.urls.deprecation branch from d868a4d to 6af2683 Compare May 3, 2023 03:23
@dairiki dairiki force-pushed the fix.werkzeug.urls.deprecation branch 2 times, most recently from 508fe93 to 4da30af Compare May 4, 2023 19:04
@dairiki dairiki marked this pull request as ready for review May 4, 2023 19:46
dairiki added a commit to dairiki/lektor that referenced this pull request May 4, 2023
Our Publisher API involves passing a `werkzeug.urls.URL` instance to
`Publisher.publish`.  As this is an API assumed by custom publishers
implemented by Lektor plugins out in the wild, we can not simply
change the API.

PR lektor#1143 — in the master branch — implements one approach to updating
the API in a backward-compatible manner, but it is rather involved.

For the sake of the 3.3.x branch, for now we pin werkzeug<2.4 and
leave the Publisher API as it is.
dairiki added a commit to dairiki/lektor-website that referenced this pull request May 4, 2023
@dairiki dairiki added this to the 3.4 milestone May 4, 2023
@dairiki dairiki force-pushed the fix.werkzeug.urls.deprecation branch from 4da30af to 3133953 Compare May 4, 2023 22:42
dairiki added a commit to dairiki/lektor that referenced this pull request May 5, 2023
Our Publisher API involves passing a `werkzeug.urls.URL` instance to
`Publisher.publish`.  As this is an API assumed by custom publishers
implemented by Lektor plugins out in the wild, we can not simply
change the API.

PR lektor#1143 — in the master branch — implements one approach to updating
the API in a backward-compatible manner, but it is rather involved.

For the sake of the 3.3.x branch, for now we pin werkzeug<2.4 and
leave the Publisher API as it is.
@dairiki dairiki merged commit 5878799 into lektor:master May 5, 2023
15 checks passed
@dairiki dairiki deleted the fix.werkzeug.urls.deprecation branch May 5, 2023 22:41
dairiki added a commit to dairiki/lektor that referenced this pull request Sep 11, 2023
* refactor: deprecate unused method Pad.make_absolute_url

* refactor!: change Url.query from URI-encoded to IRI-decoded value

* fix: disuse deprecated werkzeug.urls functions

* refactor(publisher): pass URLs as str rather than SplitResult tuples

* fix(publisher): restore compatibility with existing publisher plugins

* fix: parse_qsl has no 'separator' parameter for python < 3.7.10
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.

Deprecated Werkzeug APIs in use
1 participant