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

Versioning doesn't work with Custom middleware #8823

Closed
2 of 3 tasks
johnugeorge opened this issue Dec 31, 2022 · 1 comment
Closed
2 of 3 tasks

Versioning doesn't work with Custom middleware #8823

johnugeorge opened this issue Dec 31, 2022 · 1 comment

Comments

@johnugeorge
Copy link

johnugeorge commented Dec 31, 2022

I have enabled AcceptHeaderVersioning as the DEFAULT_VERSIONING_CLASS. I have added a custom middleware(added at the last of the MIDDLEWARE list) which looks at request.version value and take actions based on the custom logic. However, I see that request.version is not populated in the middleware and returns the error.

  File "/Users/test/opt/miniconda3/envs/test/lib/python3.9/site-packages/django/core/handlers/base.py", line 171, in _get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/Users/test/work/test1/versioncheck/middleware.py", line 35, in process_view
    print(request.version)
AttributeError: 'WSGIRequest' object has no attribute 'version'

Checklist

  • Raised initially as discussion #...
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
@tfranzel
Copy link
Member

tfranzel commented Jan 2, 2023

Pretty sure this is expected behavior. The middleware stack runs prior to view initialization and the view is actually the entity that carries the versioning class. It is imho expected to be missing on the way down the middleware stack. It should be available on the way up (after view was rendered) though.

@tomchristie tomchristie closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2024
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

No branches or pull requests

3 participants