Skip to content
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.2 Support]: AttributeError: 'WSGIRequest' object has no attribute 'is_ajax' #33035

Closed
Tracked by #198
UsamaSadiq opened this issue Aug 17, 2023 · 1 comment
Closed
Tracked by #198

Comments

@UsamaSadiq
Copy link
Member

UsamaSadiq commented Aug 17, 2023

Description

  • When running unit tests against Django 4.2, the error is being generated.
  • Investigate and fix to allow supporting Django 4.2.

Test Run Logs

FAILED cms/djangoapps/maintenance/tests.py::MaintenanceViewAccessTests::test_global_staff_access_1__maintenance_force_publish_course - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
FAILED cms/djangoapps/maintenance/tests.py::TestForcePublish::test_already_published - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
FAILED cms/djangoapps/maintenance/tests.py::TestForcePublish::test_force_publish_dry_run - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
FAILED cms/djangoapps/maintenance/tests.py::TestForcePublish::test_invalid_course_key_messages_1_______Please_provide_course_id___ - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
FAILED cms/djangoapps/maintenance/tests.py::TestForcePublish::test_invalid_course_key_messages_2___edx____Invalid_course_key___ - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
FAILED cms/djangoapps/maintenance/tests.py::TestForcePublish::test_invalid_course_key_messages_3___course_v1_e_d_X____No_matching_course_found___ - AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'
====== 6 failed, 106 passed, 26 skipped, 267 warnings in 76.29s (0:01:16) ======
@UsamaSadiq
Copy link
Member Author

UsamaSadiq commented Aug 18, 2023

request.is_ajax() was deprecated in Django 3.1 and now has been removed in Django 4.0.
Solution for the issue https://stackoverflow.com/a/70976929/20185847

Replacing

if request.is_ajax():

with

if request.headers.get('x-requested-with') == 'XMLHttpRequest':

should work.

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

No branches or pull requests

1 participant