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

Fix double EXPLAIN when calling explain on queryset #654

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stereodamage
Copy link

@stereodamage stereodamage commented Apr 23, 2023

Closes #597, #650.

There's also an idea to wrap call to database into try..except and throw something like ProgrammingError (according to PEP 249) or custom error based on ProgrammingError.

@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #654 (0416234) into master (274898f) will decrease coverage by 0.03%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
- Coverage   86.51%   86.48%   -0.03%     
==========================================
  Files          52       52              
  Lines        2091     2094       +3     
==========================================
+ Hits         1809     1811       +2     
- Misses        282      283       +1     
Impacted Files Coverage Δ
silk/sql.py 78.26% <75.00%> (-0.53%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@stereodamage stereodamage force-pushed the fix-explain branch 2 times, most recently from 10e8b7b to 2485450 Compare June 25, 2023 19:46
@pawelzar
Copy link
Member

Hey, I just encountered this issue too. I think the changes look good but test coverage is failing. I can help you add some unit tests if you'd like @stereodamage.

@@ -53,7 +54,11 @@ def _explain_query(connection, q, params):

# currently we cannot use explain() method
# for queries other than `select`
prefixed_query = f"{prefix} {q}"
if re.match(f"^{prefix} .*", q):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using just str.startswith() instead?

Suggested change
if re.match(f"^{prefix} .*", q):
if q.startswith(prefix):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that will work!

@stereodamage
Copy link
Author

@pawelzar that would be nice of you, I appreciate that. Didn't really had much time to look into it again and write new test myself. Anything needed from my side?

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

Successfully merging this pull request may close these issues.

Running queryset.explain will result in an error
2 participants