Opened 5 years ago

Closed 5 years ago

#31210 closed Cleanup/optimization (fixed)

Document backwards-compatible replacement for is_ajax().

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

Description

is_ajax() was deprecated in #30997.

I think the release/upgrading notes should mention request.is_ajax() can be replaced with request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' to maintain the old behavior.

https://github.com/django/django/blob/e348ab0d4382b0d7cb0cab9d1261c916c3d0ce6c/django/http/request.py#L260-L266

Change History (7)

comment:1 by Collin Anderson, 5 years ago

Cc: Collin Anderson added
Component: DocumentationHTTP handling
Needs documentation: set

In fact, the deprecation warning message itself could maybe even mention the backwards-compatible replacement.

(I'm hoping this way the upgrade/migration process could be as easy as possible.)

Last edited 5 years ago by Collin Anderson (previous) (diff)

comment:2 by Mariusz Felisiak, 5 years ago

We documented using the HttpRequest.accepts() or writing a custom AJAX detection method as recommended replacements:

Depending on your use case, you can either write your own AJAX detection method, or use the new HttpRequest.accepts() method if your code depends on the client "Accept" HTTP header.

Do you think that we should be so detailed and document the is_ajax() implementation in release notes? I'm not sure.

comment:3 by SUTHARRAM, 5 years ago

Owner: changed from nobody to SUTHARRAM
Status: newassigned

comment:4 by Collin Anderson, 5 years ago

I'm just thinking if someone's trying to upgrade their app to use a new version of django, the most minimal change with the least chance of bugs would be to replace it with request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' (or a separate function/method that does exactly that). Sure, they could refactor their app so it uses .accepts(), but that's a bigger change (which could involve making changes on the front end, which might be a whole different team responsibly for it) and they're just trying to upgrade django right now.

Do you think that we should be so detailed and document the is_ajax() implementation in release notes? I'm not sure.

Yes, otherwise, they're probably going to need to look it up. Especially considering it's only one line of code, why not make it easy for them?

Last edited 5 years ago by Collin Anderson (previous) (diff)

comment:5 by Mariusz Felisiak, 5 years ago

Needs documentation: unset
Summary: Document backwards-compatible replacement for is_ajax()Document backwards-compatible replacement for is_ajax().
Triage Stage: UnreviewedAccepted

Agreed, we can add a short snippet to release notes.

comment:6 by Adam Johnson, 5 years ago

Has patch: set
Owner: changed from SUTHARRAM to Adam Johnson

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

Resolution: fixed
Status: assignedclosed

In 469bf2db:

Fixed #31210 -- Doc'd how to reproduce HttpRequest.is_ajax() in release notes.

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