django-stubs
django-stubs copied to clipboard
"_MonkeyPatchedWSGIResponse" has no attribute "data"
"_MonkeyPatchedWSGIResponse" has no attribute "data" test.py:106: error: "_MonkeyPatchedWSGIResponse" has no attribute "data" [attr-defined]sop/tests/test_task_copy.py:106: error: "_MonkeyPatchedWSGIResponse" has no attribute "data" [attr-defined]
Does anyone know why this is?
Why do you think data
attribute should exist? I could be missing something, but I don't see it in any of the Django BaseHttpResponse
classes.
JsonResponse()
accepts a data=
constructor argument, but it's not assigned to a property named data
.
Also don't see it documented here: https://docs.djangoproject.com/en/5.0/topics/testing/tools/ (only has data=
argument on request methods)
Could this be related to Django Rest Framework?
Because I had the same issue when using django.test.TransactionTestCase
instead of rest_framework.test.APITransactionTestCase
.
Somehow responses from self.client
still had the data property, which are a feature of APIClient
(s. https://www.django-rest-framework.org/api-guide/testing/#checking-the-response-data).
The fix would be to use the correct TestCase class, however I'm not sure why the property is there in the first place when using the vanilla Django TestCase.