-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixes #1239 #1475
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
Fixes #1239 #1475
Conversation
This is just PoC. I wouldn't know how to test this properly.
Oh wow, that's all it took? Do you have any idea how many times the cursor got wrapped? "Only" twice or more? |
Codecov Report
@@ Coverage Diff @@
## main #1475 +/- ##
==========================================
- Coverage 86.34% 86.26% -0.09%
==========================================
Files 35 35
Lines 1853 1856 +3
Branches 260 261 +1
==========================================
+ Hits 1600 1601 +1
- Misses 181 182 +1
- Partials 72 73 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW This is ≈ how I fixed it when I hit this issue.
I got stumped on how to write a test for this, and never had the time to get past that, but...
@carltongibson Thanks :) @saemideluxe We get some test failures on PostgreSQL; the chunked cursor test fails. Do you have the time to look into this? |
@matthiask I will look into over the weekend. |
The test for the What I do not understand is why with postgresql we get do not get a wrapped cursor but with other databases we get a wrapped cursor... Maybe this is related to the fact that |
Nice, thanks! Is there a reason why you're checking for
I'm not sure and didn't dig into it. My stance is that the code is perfect if tests pass (well not really but it's somewhat true) |
Right, just changed that to |
Thanks! |
Is there any chance we'd want a similar fix for the non-chunked cursor equivalent, or does #1239 only affect chunked fetches for some reason? |
According to the conversation in #1239 it only seems to affect chunked cursors (also my experience). The initial author investigated the behaviour somewhat it seems. But I couldn't rule it out for sure because I did not have the time to dig into the cause of having wrapped cursors in the first place. |
Ahh, ok, thanks @saemideluxe - yep, this is starting to make more sense to me now. I'm repeating a bit of the discussion I suppose, but hopefully it's worthwhile to understand. If I understand it now, it's the fact that -- for some database providers -- a method call to To put it another way: for the problem to appear, both cursor methods have to be called -- usually accidentally -- in the context of the same database query, and in the same call stack. The fix uses the fact Supporting the approach, certainly Django since way back considers database support for chunked reads to be an optional ability, and the introduction of |
Thanks for the elaborations and the links @jayaddison |
No problem, thank you for the fix :) It'll make SQL performance debugging much less confusing for a lot of Django users. There is a possible way to test this in #1478, although I think that's slightly incompatible at the moment. I have another question during writing the tests: is |
Since there's no way for this attribute to change between the The common base class may still be a good idea for other reasons but I'm not sure it's necessary. |
Makes sense, thanks @matthiask. I've opened #1479 with that possible refactor. |
This is just PoC. I wouldn't know how to test this properly.