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

HttpResponse has no 'data' on 0.4.0 #237

Closed
mbaragiola opened this issue Sep 18, 2018 · 10 comments
Closed

HttpResponse has no 'data' on 0.4.0 #237

mbaragiola opened this issue Sep 18, 2018 · 10 comments

Comments

@mbaragiola
Copy link

mbaragiola commented Sep 18, 2018

Hey guys, just tried updating to 0.4.0 and it broke all my tests.

Whenever I do a GET to a filtered cached list, I run the following test to check wether the amount of objects returned is ok:

self.assertEqual(
    response.data['count'],
    3
)

But now I get the following error:

AttributeError: 'HttpResponse' object has no attribute 'data'

Django is 1.11.15, DRF is 3.8.2 and Python is 3.6 (haven't changed their versions, just drf-extensions).

Thanks in advance!

EDIT: Forgot to mention this is a cached list.

@auvipy
Copy link
Collaborator

auvipy commented Sep 18, 2018

@codingjoe could you check as you made the change?

@codingjoe
Copy link
Contributor

Hi @mbaragiola that looks like it is related to the caching change it did here:
bdce9e0

I would recommend to disable caching in your test environment. If you want to test the cached behavior, need to be aware the the cached response is a regular Django HttpResponse not the special DRF one.

@codingjoe
Copy link
Contributor

Maybe that should be documented somewhere... but I don't know which place would fit this kind of specialized note.

@auvipy
Copy link
Collaborator

auvipy commented Sep 19, 2018

you can add a BC breaking note on release note of 0.4.0

@mbaragiola
Copy link
Author

@auvipy @codingjoe thanks for replying!

I'm curious, what's the reason behind this change? Since this is an extension to DRF and not Django itself.

Testing cache is critical to me, so I'm trying to find a workaround but I can't so far access serialized data on HttpResponse.

@auvipy
Copy link
Collaborator

auvipy commented Sep 19, 2018

@codingjoe I also think since it's an extension of drf, we should be able to do so, since its a breaking change, I think if there isn't any workaround for it, we should revert the change. do you have any drfish solution in mind?

@codingjoe
Copy link
Contributor

Sorry I need to call for a bit more caution here. Some like – my company included – may already use the improved cache feature. If you revert it now, that could be considered a breaking change as well ;)

@mbaragiola to give you a bit more context. Caching a DRF response as is pickling the whole object is not a good idea. The DRF response object is too large and can even include whole Querysets.
The change that I introduced only caches the actual HTTP response and forgets everything else.

Form a user perspective this change it totally acceptable and we experienced a >100x improvement on delivery time as well as memory footprint on our caching servers. So this really only breaks your tests, because you assume the response to be a DRF response.

I see only possible solutions here, we document that the cache features will return regular HTTPResponses and make sure it is consistent. You will need to adapt your tests then.

"Breaking" the cache again, by blowing it up seems not reasonable to me. I also don't really see a way to cache the original DRF response in a way that satisfies the main need of a cache: To be fast.

That is of course only my opinion, but I hope it explains my reasoning a bit better.

@mbaragiola
Copy link
Author

mbaragiola commented Sep 24, 2018

If that's truly the case, then I agree @codingjoe. Thank you for explaining!

@auvipy
Copy link
Collaborator

auvipy commented Sep 25, 2018

@codingjoe could you please send a pr explaining so?

@codingjoe
Copy link
Contributor

sure thing, see #240

@auvipy auvipy closed this as completed in 1917b7f Oct 6, 2018
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

3 participants