django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

`query_params` is a property of the DRF request object, but not the request object returned by APIRequestFactory

Open tstirrat15 opened this issue 6 years ago • 7 comments

Checklist

  • [x] I have verified that that issue exists against the master branch 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?

tstirrat15 avatar Mar 04 '19 23:03 tstirrat15

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...

carltongibson avatar Mar 05 '19 08:03 carltongibson

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.

rpkilby avatar Mar 06 '19 21:03 rpkilby

is there still no good solution to this?

striveforbest avatar Dec 15 '21 23:12 striveforbest

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.

stale[bot] avatar Apr 17 '22 03:04 stale[bot]

I think this issue is still relevant and to fix this would improve testing of DRF.

sliverc avatar Apr 18 '22 07:04 sliverc

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.

stale[bot] avatar Jun 20 '22 02:06 stale[bot]

This is still relevant. Unfortunately no time to work on a PR myself but maybe someone else does.

sliverc avatar Jun 25 '22 13:06 sliverc

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.

stale[bot] avatar Nov 02 '22 00:11 stale[bot]

Still relevant.

reify-tanner-stirrat avatar Nov 02 '22 02:11 reify-tanner-stirrat

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.

stale[bot] avatar Jan 07 '23 14:01 stale[bot]

contribution to fix this, would be highly appreciated.

auvipy avatar Jan 07 '23 15:01 auvipy