Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#30997 closed Cleanup/optimization (fixed)

Deprecate HttpRequest.is_ajax.

Reported by: Adam Johnson Owned by: nobody
Component: HTTP handling Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

As discussed on this django-developers thread this should be deprecated.

It inspects the non-standard header X-Requested-Wiith that is set by jQuery and maybe other frameworks. However jQuery's popularity, especially for making requests, is decreasing thanks to changes such as the new fetch() JS API.

Also in the cases this property is used to determine the kind of content to send to a client, it'd be better to inspect the HTTP standard Accept header.

For these reasons Flask has deprecated its similar property is_xhr.

Change History (12)

comment:1 Changed 3 years ago by Mariusz Felisiak

Description: modified (diff)
Summary: Deprecate HttpRequest.is_ajaxDeprecate HttpRequest.is_ajax.
Triage Stage: UnreviewedAccepted

comment:2 Changed 3 years ago by Claude Paroz

The first step would be to document current limitations of the method.
Second step would be to avoid using it as much as possible in Django's own code.
Finally the deprecation can take place.

It remains to be shown how the request.accepts proposal can play a role here.
A good exercise would be to replace that example: https://docs.djangoproject.com/en/2.2/topics/class-based-views/generic-editing/#ajax-example (or would you simply remove it?)

comment:3 Changed 3 years ago by Claude Paroz

Has patch: set

I modified a bit the requests.accept() PR to include what is IMHO needed before deprecating the is_ajax method.

comment:4 Changed 3 years ago by Jakub Sobczak

By deprecate do you just mean removing it from code base?

comment:6 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In d66d72f:

Refs #30997 -- Added HttpRequest.accepts().

comment:7 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In 7fa0fa4:

Refs #30997 -- Removed HttpRequest.is_ajax() usage.

comment:8 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: newclosed

In e348ab0:

Fixed #30997 -- Deprecated HttpRequest.is_ajax().

comment:9 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In c9bf191:

Refs #30997 -- Added link to Fetch API in release notes.

comment:10 Changed 3 years ago by GitHub <noreply@…>

In 7fc317a:

Refs #30997 -- Improved HttpRequest.is_ajax() warning message with stacklevel=2.

comment:11 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In 619e3db:

[3.1.x] Refs #30997 -- Improved HttpRequest.is_ajax() warning message with stacklevel=2.

Backport of 7fc317ae736e8fda1aaf4d4ede84d95fffaf5281 from master

comment:12 Changed 2 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In d08977a0:

Refs #30997 -- Removed HttpRequest.is_ajax() per deprecation timeline.

Note: See TracTickets for help on using tickets.
Back to Top