-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
New template middleware causing an issue? #5034
Comments
Sorry, Elisa, this one has to go to you. I set it for the next sprint as a high priority, but if something jumps out at you, maybe an opinion now would be helpful to @v-anne. |
If it helps with debugging, there was a ~50/50 chance that clicking the page buttons worked. Sometimes, they would go to the correct page, but other times, they would throw up the error shown above. |
Literally 50/50 or roughly 50/50? |
Roughly. I tested approximately ten times, I think it broke approximately six of them? I will rerun it if necessary. |
I noticed the view is an async one, and I don't have much experience with them, but I wonder if it's possible for the middleware to pick up on the request before the |
We have a bunch of async views. If this was an async thing, I'd expect it to affect lots of them. |
Makes sense, but couldn't it maybe be an error visibility issue? Maybe other views are being affected but we just haven't noticed it yet. I'd have to look deeper into it, but I think it would help to know if this definitely never ever happens without the changes introduced by that PR. Do we have other async views with pagination? If we do not have other async views with pagination (couldn't find any with a very quick grep), and this error is only happening with the changes introduced by the PR, I guess it'd be safe to assume there's an issue with the pagination, wouldn't it? |
We almost always know about bugs that affect multiple pages either via Sentry or user reports, but sometimes they get missed, I suppose. Could certainly be pagination causing it, yeah, but I don't know why pagination would affect this middleware. Interesting. There is documentation on async middlewares: https://docs.djangoproject.com/en/5.1/topics/http/middleware/#async-middleware |
Hi @elisa-a-v and @mlissner, I've been reviewing #4956 and have successfully reproduced the problem. The issue appears to be limited to views using the I think we can use the I've implemented the following tweak to the middleware code to address this issue and resolve the exception: class IncrementalNewTemplateMiddleware:
def process_template_response(self, request, response):
use_new_design = flag_is_active(request, "use_new_design")
- if use_new_design and isinstance(response, TemplateResponse):
+ if (
+ use_new_design
+ and isinstance(response, TemplateResponse)
+ and not response.is_rendered
+ ):
old_template = response.template_name
if isinstance(old_template, str):
new_template = f"v2_{old_template}"
response.template_name = [new_template, old_template]
return response |
Is that middleware tweak in the Pray and Pay PR? Are we using that decorator elsewhere? |
In #4956, @v-anne reports that they're having a problem with the new template middleware. They're working on adding pagination, but when they do, they say:
The buttons for the pagination show up fine, but when I try clicking them this shows up:
Originally posted by @v-anne in #4956 (comment)
The text was updated successfully, but these errors were encountered: