-
Notifications
You must be signed in to change notification settings - Fork 32
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
RFC 93: Redirect improvements #93
base: main
Are you sure you want to change the base?
Conversation
In Django 4.2, the redirect only happens in `process_response`, so Wagtail kicks in first.
1afc664
to
757f992
Compare
|
||
### Open questions | ||
|
||
1. Should we also confirm whether the `old_path` matches an existing view? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is well worth flagging. i.e. "There is an existing system path that may stop working. Are you sure?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this still be relevant if redirects continue to only come into play in the event of a 404?
text/093-redirect-improvements.md
Outdated
|
||
An `is_eager` column will be added to a `Redirect`, which flags whether the redirect should run before the rest of the Wagtail page process, or afterwards (as they would currently). `is_eager` will default to `False`, to ensure it's not a breaking change, or impact other site behaviours. | ||
|
||
To properly support `is_eager`, the `RedirectMiddleware` will also need bringing up the `MIDDLEWARES` list, below incredibly high middleware such as `SecurityMiddleware`, `GzipMiddleware` and `WhitenoiseMiddleware`, but still as high as possible. Unfortunately, this will impact performance, as a database query will need to be made for redirects on every request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one that doesn't sit well with me at the moment. I can see pitchforks being raised :)
What if we provide a separate, EagerRedirectMiddleware
for just this? Plenty of Wagtail sites are perfectly fine with the current setup
|
||
### Specification | ||
|
||
I propose Wagtail automatically update URL redirects which point to Wagtail pages to reference the page instead. An example implementation exists in [#6465](https://github.com/wagtail/wagtail/issues/6465). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to account for i18n-prefixed URLs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localisation may make this a lot more complex (but is also something we need to account for). For example, if we want to redirect to a page with multiple translations, what URL do we redirect to?
|
||
### Specification | ||
|
||
As part of the redirect creation process, redirects will confirm that the source and destination URL are different. This is relatively simple to determine for single-site deployments: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this get in the way of people manually setting up redirects in advance of taking certain actions (E.g. Moving a group of pages) when automatic redirect creation is disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, yes, and so would require automatic redirections to properly kick in. We could make this validation opt-out.
Django 4.2 makes this a lot better, and eager redirects can severely impact performance and introduce potential foot-guns.
For background, the use-case that originally prompted the desire to validate against circular redirects was a site that added various With eager redirects out of the picture (no longer required as of Django 4.2 due to django/django@fbac2a4), it seems to me that the usefulness of this becomes more marginal, since this redirect loop would only happen if the destination was a 404 (in which case the redirect would not be doing anything useful even if it were working correctly). Having said that, there's no real downside to having this validation in place, so happy to go ahead with adding it. |
I take it the idea here is to provide some sort of feedback to the user to indicate "this redirect won't trigger because its URL corresponds to an existing page"? I can see the value in that, but I think it's different enough from the focus of this RFC, and hard enough to get right, that we shouldn't try to tackle it here. (Presumably in many / most cases, old_path will indeed pattern-match against at least one view at the urlconf level - namely, |
[Converting URL redirects to page redirects]
My gut feeling is that converting them automatically is possibly more "magic" than we really want - it's overriding what the user specifically asked to do, with what the system thinks they meant to do, and I could imagine situations where it gets it wrong. Something along the lines of:
|
Picking this up again for 6.2 planning... I think we're happy to go ahead with validating against circular redirects, as per #11659. Re converting URL redirects to page redirects - as per above, I don't think this should happen automatically. A UI for prompting users about this might look something like: On submitting the "add redirect" form, if the external URL field has been filled in, parse it and run it through Wagtail's routing logic. If this resolves to a page, AND that page's
These buttons will be linked to hidden forms; the "yes" button will submit a replica of the original form with the page ID populated and the URL field cleared, while the "no" button will submit a replica of the original form with an additional flag to skip the routing check. This workflow will only work for adding a single redirect, not bulk uploading - are we happy to treat the latter as out of scope, or do we need to account for that too? |
I would say that's a fair compromise. But, I am slightly concerned about giving developers / admins / editors a false sense of security here... It's very easy to assume that because Wagtail treats individual redirects one way, it also does something about batches (whether visible or not), and therefore assume it's something they don't need to consider. Is there anything we could do to alleviate this? |
Add an RFC (as discussed internally) for adding a few useful features to redirects.
View rendered version