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]: Fix: object has no attribute 'is_ajax' #33134

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

irtazaakram
Copy link
Member

Description

Fixes issue when upgrading to Django 4.2

/usr/lib/python3.8/unittest/mock.py:637: AttributeError
___________ TestCommonExceptions400.test_alreadyrunningerror_2_False ___________

self = <lms.djangoapps.instructor.tests.test_api.TestCommonExceptions400 testMethod=test_alreadyrunningerror_2_False>
is_ajax = False

    @ddt.data(True, False)
    def test_alreadyrunningerror(self, is_ajax):
>       self.request.is_ajax.return_value = is_ajax

lms/djangoapps/instructor/tests/test_api.py:279: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Mock spec='HttpRequest' id='140253030049632'>, name = 'is_ajax'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
>               raise AttributeError("Mock object has no attribute %r" % name)
E               AttributeError: Mock object has no attribute 'is_ajax'

Django docs
https://docs.djangoproject.com/en/3.1/releases/3.1/#id2

The HttpRequest.is_ajax() method is deprecated as it relied on a jQuery-specific way of signifying AJAX calls, while current usage tends to use the JavaScript Fetch API. 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.

Reference
#33055

@awais786 awais786 merged commit 4773f14 into master Aug 30, 2023
42 checks passed
@awais786 awais786 deleted the fix-is_ajax-issue branch August 30, 2023 09:18
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

Yagnesh1998 pushed a commit to ManpraXSoftware/edx-platform that referenced this pull request Sep 1, 2023
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.

3 participants