Skip to content

Remove calls to deprecated request.is_ajax() #1382

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

Merged
merged 1 commit into from
Oct 15, 2020
Merged

Remove calls to deprecated request.is_ajax() #1382

merged 1 commit into from
Oct 15, 2020

Conversation

jdufresne
Copy link
Contributor

Since Django 3.1, the method request.is_ajax() is deprecated and will be
removed in a future version. Using Django 3.1 with django-debug-toolbar
results in the warning:

django-debug-toolbar/debug_toolbar/middleware.py:80: RemovedInDjango40Warning: request.is_ajax() is deprecated. See Django 3.1 release notes for more details about this deprecation.
  request.is_ajax(),

The calls were removed with no replacements as these check are
unnecessary anyway. If the response is not HTML (e.g. JSON) then the
check or content_type not in _HTML_TYPES will evaluate as false and
the toolbar will not be included in the response. If the response is an
HTML fragment, it will not contain an </body> element (the
INSERT_BEFORE pattern) and so will also not be included in the response.

Fixes #1368

Since Django 3.1, the method request.is_ajax() is deprecated and will be
removed in a future version. Using Django 3.1 with django-debug-toolbar
results in the warning:

    django-debug-toolbar/debug_toolbar/middleware.py:80: RemovedInDjango40Warning: request.is_ajax() is deprecated. See Django 3.1 release notes for more details about this deprecation.
      request.is_ajax(),

The calls were removed with no replacements as these check are
unnecessary anyway. If the response is not HTML (e.g. JSON) then the
check `or content_type not in _HTML_TYPES` will evaluate as false and
the toolbar will not be included in the response. If the response is an
HTML fragment, it will not contain an `</body>` element (the
INSERT_BEFORE pattern) and so will also not be included in the response.

Fixes #1368
@codecov
Copy link

codecov bot commented Oct 11, 2020

Codecov Report

Merging #1382 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1382      +/-   ##
==========================================
+ Coverage   87.83%   87.88%   +0.05%     
==========================================
  Files          29       29              
  Lines        1578     1577       -1     
  Branches      222      221       -1     
==========================================
  Hits         1386     1386              
  Misses        141      141              
+ Partials       51       50       -1     
Impacted Files Coverage Δ
debug_toolbar/middleware.py 96.66% <100.00%> (+1.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9119982...b0d07b1. Read the comment docs.

@matthiask matthiask merged commit 4de5021 into django-commons:master Oct 15, 2020
@matthiask
Copy link
Member

Thank you! The explanation makes a lot of sense to me. Nice that we can simply drop the is_ajax calls.

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

Successfully merging this pull request may close these issues.

Remove calls to request.is_ajax?
2 participants