`query_params` is a property of the DRF request object, but not the request object returned by APIRequestFactory
Checklist
- [x] I have verified that that issue exists against the
masterbranch of Django REST framework. - [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [x] This is not a usage question. (Those should be directed to the discussion group instead.)
- [x] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- [x] I have reduced the issue to the simplest possible case.
- [x] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
from rest_framework.test APIRequestFactory
def test_request_factory_get_request_has_query_params():
assert APIRequestFactory().get('/', { 'foo': 'bar' }).query_params
Expected behavior
Pass
Actual behavior
AttributeError
Is there an easy way around this? Otherwise, is there a place/way that you'd prefer me to make the necessary modifications?
This looks like a Duplicate of #4440. That was close but this comment was added:
https://github.com/encode/django-rest-framework/issues/4440#issuecomment-244053745
Aside: I have warmed to the idea of ensuring that this returns a fully fledged Request instance, and having views be able to handle either, so this might come up in the future.
Probably time to fix that...
At a minimum, we need an easy way of creating fully fledged DRF requests. Several of our tests use dummy views to get the fully created request/response/view instance.
https://github.com/encode/django-rest-framework/blob/739b0a272a66d9beb7afb7490f201d71d7cdc910/tests/test_renderers.py#L733-L746
That said, any solution would need to initialize the fully fledged DRF request with a view, given that the DRF request needs to be initialized with the view's authenticators, permissions, etc...
What I'm thinking is the factory could provide a helper that returns the request, response and view instance all at once. I don't think we could return a fully fledged request without going through the whole view lifecycle, since this gets back to the issue of double parsing the underlying request body.
Although, not sure how this would work with viewsets/routers.
is there still no good solution to this?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I think this issue is still relevant and to fix this would improve testing of DRF.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is still relevant. Unfortunately no time to work on a PR myself but maybe someone else does.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still relevant.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
contribution to fix this, would be highly appreciated.