-
Notifications
You must be signed in to change notification settings - Fork 468
django 4.0 support #3067
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
django 4.0 support #3067
Conversation
e684028 to
543ca95
Compare
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.
Diff between snapshot generated by django 4 and django 2.2 for test_safe_string_endocing
Django 4 instrumentation appends the name of the ListView class to the resource name of a django.view span.
{
"name": "django.view",
"service": "django",
- "resource": "tests.contrib.django.views.view",
+ "resource": "tests.contrib.django.views.SafeTemplateUserList",
"trace_id": 0,
"span_id": 26,
"parent_id": 23,
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.
can you add this to the PR description as well as a change
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 the other way around right? We lose SafeTemplateUserList for some reason in Django 4 and get tests.contrib.django.views.view instead?
Seems odd... maybe something changed in .as_view()? We should probably figure out why this changed since it could be breaking if a user has a facet on the resource of django view spans.
543ca95 to
62e013b
Compare
62e013b to
29f9cf6
Compare
brettlangdon
left a comment
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.
Remove references to dgango.urls.url
in PR description, should be django.urls.url
also, this will need a release note
| if django.VERSION >= (4, 0, 0): | ||
| CACHES["redis"]["BACKEND"] = "django.core.cache.backends.redis.RedisCache" |
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 might be cleaner to organize as... before CACHES is defined:
redis_backend = "django_redis.cache.RedisCache"
if django.VERSION >= (4, 0, 0):
redis_backend = "django.core.cache.backends.redis.RedisCache"
CACHES = {
...
"redis": {
"BACKEND": redis_backend,
"LOCATION": "..."
},
...
}a little cleaner than reaching into the nested dict later
| if django.VERSION < (2, 0, 0): | ||
| from django.conf.urls import url | ||
| else: | ||
| from django.urls import re_path as url |
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.
we probably shouldn't do this, don't want to confuse anyone looking at all of the urlpatterns and expecting django.conf.urls.url instead of re_path.
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 also a django 1.x app, why do we need this change?
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 I'd prefer to just import re_path and use that instead rather than mapping it to url
| } | ||
|
|
||
| if django.VERSION >= (4, 0, 0): | ||
| CACHES["redis"]["BACKEND"] = "django.core.cache.backends.redis.RedisCache" |
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.
same here
| from .. import views | ||
|
|
||
|
|
||
| if django.VERSION < (2, 0, 0): |
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 shouldn't be used with django 1 right, so is this needed?
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.
Nope but this was a mistake that line should be django.VERSION < (4, 0, 0). I'd like to keep test coverage for django.conf.urls.url for django 2
| if django.VERSION < (2, 0, 0): | ||
| from django.conf.urls import url | ||
| else: | ||
| from django.urls import re_path as url |
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.
same here as above
| if django.VERSION < (2, 0, 0): | ||
| from django.conf.urls import url | ||
| else: | ||
| from django.urls import re_path as url |
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.
same here, do we even test django_hosts with django 1?
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.
Nope min version is 2.2. Good catch
|
|
||
|
|
||
| if django.VERSION < (2, 0, 0): | ||
| from django.conf.urls import url |
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.
same here
| if django.VERSION < (2, 0, 0): | ||
| from django.conf.urls import url | ||
| else: | ||
| from django.urls import re_path as url |
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.
same as above, I'd prefer not to remap re_path to url
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 mapped it to "handler". The reason why I made this change was to keep this pr small. In hindsight I should've prioritized readability
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.
can you add this to the PR description as well as a change
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
…o munir/django-4.0
…o munir/django-4.0
|
|
||
|
|
||
| # django version < 2 does not support django.urls.re_path | ||
| # django version > 3 does not support django.conf.urls.url |
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.
You mean >=4.0?
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.
Also, we should be testing both when possible
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.
Yup, it's deprecated in django 3 but it's still supported
e90d4b5 to
f39707e
Compare
efb7fc7 to
d3d2d09
Compare
…o munir/django-4.0
d3d2d09 to
76ebe12
Compare
Codecov Report
@@ Coverage Diff @@
## master #3067 +/- ##
==========================================
- Coverage 84.56% 84.54% -0.02%
==========================================
Files 638 638
Lines 46069 46262 +193
==========================================
+ Hits 38957 39114 +157
- Misses 7112 7148 +36
Continue to review full report at Codecov.
|
Kyle-Verhoog
left a comment
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.
Looks good! Just a question about the subtle change to the view resource name and the docs. Otherwise lgtm
| --- | ||
| features: | ||
| - | | ||
| Add django 4.0 support. No newline at end of file |
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.
Also have to update integrations.rst
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 the other way around right? We lose SafeTemplateUserList for some reason in Django 4 and get tests.contrib.django.views.view instead?
Seems odd... maybe something changed in .as_view()? We should probably figure out why this changed since it could be breaking if a user has a facet on the resource of django view spans.
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
…iew(), in django 4 View.__name__ returns 'view' and not the name of the sub class of django.views.generic.View
…o munir/django-4.0
…o munir/django-4.0
…o munir/django-4.0
| log.debug("Failed to instrument Django view %r", instance, exc_info=True) | ||
| view = func(*args, **kwargs) | ||
| return wrapt.FunctionWrapper(view, traced_func(django, "django.view", resource=func_name(view))) | ||
| return wrapt.FunctionWrapper(view, traced_func(django, "django.view", resource=func_name(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.
In the func_name method view.__class__.__name__ returns "view" in django 4.0 instead of the name of the sub class (ex. tests.contrib.django.views.SomeViewClass). According to this comment, django 4.0 supports accessing the name of a View using theview_class attribute. Instead of this approach this change access the class name using an instance of a view and not view method. This approach is backwards compatible and can be used with the existing func_name utility.
Comments have been addressed
Add support for django 4.0
Checklist