-
Notifications
You must be signed in to change notification settings - Fork 768
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 test Client headers for Django 4.2 #1465
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,3 +145,18 @@ def bypass_get_queryset(resolver): | |
""" | ||
resolver._bypass_get_queryset = True | ||
return resolver | ||
|
||
|
||
def __django_version(): | ||
from pkg_resources import get_distribution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usage of How about using: from django import VERSION
print(VERSION)
# (4, 1, 11, 'final', 0) instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like @sjdemartini beat me to it |
||
|
||
return get_distribution("django").parsed_version | ||
|
||
|
||
def __parse_version(v): | ||
from pkg_resources import parse_version | ||
|
||
return parse_version(v) | ||
|
||
|
||
_DJANGO_VERSION_AT_LEAST_4_2 = __django_version() >= __parse_version("4.2") |
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.
There's a warning at the top here https://setuptools.pypa.io/en/latest/pkg_resources.html saying
Instead of
parse_version()
, it looks like we could use https://packaging.pypa.io/en/stable/version.html (from packaging.version import parse
). And for getting the currently-installed django version string, it looks likeimport django; django.get_version()
would work (or alternativelyimportlib.metadata.version
seems to be the substitute forget_distribution("...").parsed_version
).Unsure how important this deprecation warning is, but seems like it may be worthwhile to avoid the new code depending on this, as they suggest.
Another alternative could be something like this (if we want to avoid
packaging
for instance):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.
@sjdemartini @superlevure Thanks for the review. I know about
pkg_resources
being deprecated in favor ofimportlib...
modules. However went forpkg_resources.get_distribution("...").parsed_version
here since we need to compare 2 semvers whileimportlib.metadata.version
only returns the version string, unparsed.django.VERSION
looks like exactly what we need which I was not aware of. Will convert to that. Thanks for pointing that out!