question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpResponse has no 'data' on 0.4.0

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
codingjoecommented, Sep 24, 2018

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.

1reaction
auvipycommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

XMLHttpRequest status 0 (responseText is empty)
status is 0 when your html file containing the script is opened in the browser via the file scheme. Make sure to place...
Read more >
Source code for newrelic_telemetry_sdk.client
HTTPResponse ): """Response object with helper methods :ivar headers: The HTTP ... The HTTP status code :ivar data: The raw byte encoded response...
Read more >
List of HTTP status codes - Wikipedia
This is a list of Hypertext Transfer Protocol (HTTP) response status codes. ... the last two digits do not have any classifying or...
Read more >
Req 1.0.0, HTTP client, and streaming - Posts
And for comparison, here is also what http-client has: ... Although the data constructor of Request is not exported, checkResponse is still ...
Read more >
Changelog - Vcr - Relish
Yanked 1.10.1 and rebuilt gem on 1.8.7 to deal with syck/psych ... extends the Net::HTTP response body string with a module containing additional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found