Opened 5 years ago

Closed 5 years ago

Last modified 4 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 by Mariusz Felisiak, 5 years ago

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

comment:2 by Claude Paroz, 5 years ago

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 by Claude Paroz, 5 years ago

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 by Jakub Sobczak, 5 years ago

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

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In d66d72f:

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

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 7fa0fa4:

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

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: newclosed

In e348ab0:

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

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In c9bf191:

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

comment:10 by GitHub <noreply@…>, 5 years ago

In 7fc317a:

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

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 619e3db:

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

Backport of 7fc317ae736e8fda1aaf4d4ede84d95fffaf5281 from master

comment:12 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In d08977a0:

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

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