Skip to content

Use cursor.mogrify when available #203

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

Merged
merged 10 commits into from Mar 21, 2019
Merged

Use cursor.mogrify when available #203

merged 10 commits into from Mar 21, 2019

Conversation

mlennon-lumere
Copy link
Contributor

Instead of trying to reimplement sql formatting, use cursor.mogrify when it is available. This is implemented by psycopg2 precisely in order to get the SQL as it would be sent to the server via cursor.execute

http://initd.org/psycopg/docs/cursor.html#cursor.mogrify
Fix for #201

@codecov-io
Copy link

codecov-io commented Dec 12, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@afe0232). Click here to learn what that means.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #203   +/-   ##
=========================================
  Coverage          ?   76.09%           
=========================================
  Files             ?       29           
  Lines             ?     2389           
  Branches          ?      409           
=========================================
  Hits              ?     1818           
  Misses            ?      423           
  Partials          ?      148
Impacted Files Coverage Δ
sentry_sdk/integrations/django/__init__.py 82.84% <60%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afe0232...c50e82f. Read the comment docs.

@untitaker
Copy link
Member

@mlennon-lumere I pushed what I have right now but I probably won't get around to it this week. As stated in the linked issue the problem is that none of this is properly tested.

@mlennon-lumere
Copy link
Contributor Author

I think there could be tests added here. But the reason I'd prefer this approach instead of what's in #202 is that with the approach in #202, you'd have to have a case to handle each and every thing that psycopg2 could throw at you.

For example, sql.Placeholder instances, or sql.Literal instances, or other classes that psycopg2 hasn't even developed yet.

By standing on their shoulders with mogrify, sentry-python should be able to get their updates and keep feature-parity for much less effort

@untitaker
Copy link
Member

untitaker commented Dec 13, 2018

Yes I closed #202 because I think this is the superior approach. It's still harder to test though. A test like "assert that our integration calls mogrify" without actually having a real psycopg cursor isn't good enough I think, considering all the bugs we have ran into

@mlennon-lumere
Copy link
Contributor Author

Is this still being worked on? Cheers

@untitaker
Copy link
Member

Sorry, we've been really busy with non-sdk related stuff recently. I'll try to make some room for this. As far as I remember I was unhappy with the tests.

@mlennon-lumere
Copy link
Contributor Author

We're hoping to get these changes upstream, so we can stop relying on our fork. Do you need something else to get this done, or is simple patience the way to go?

Thanks!

@untitaker
Copy link
Member

I really want to merge this with decent tests only. Right now we don't have any other customer/user complaining about this so it's kind of low-priority

@untitaker untitaker force-pushed the master branch 3 times, most recently from 7c71749 to 1d380f7 Compare February 24, 2019 14:34
@mlennon-lumere
Copy link
Contributor Author

What sort of unit tests do you believe are missing? I'm hoping to see this get in, our org needs it to be able to keep using sentry.

Looking at the tests output is difficult, as many of the test runs on travis failed because of hitting an API rate limit. Can you guide as to what you'd like to see?

Thanks

@untitaker
Copy link
Member

@mlennon-lumere I merged master into this branch, I hope the errors are now clearer. We recently added a CONTRIBUTING.md which should make it easier for you to set up a local dev env.

This has been a long time ago, but I believe the issue here was that we configured a sqlite database while testing postgres specific stuff. This has already caused some issues in the past, but so far we've been able to get away with it even though the query crashed halfway through.

@mlennon-lumere
Copy link
Contributor Author

I'm not sure what's going on with the celery tests breaking - thanks for having a look and fixing the bytestring issues, postgres config

@untitaker
Copy link
Member

Seems unrelated. Thanks for the PR!

@untitaker untitaker merged commit 807c319 into getsentry:master Mar 21, 2019
@mlennon-lumere
Copy link
Contributor Author

Thanks for merging - when can we expect a release?

Thanks again

@untitaker
Copy link
Member

untitaker commented Mar 25, 2019 via email

@untitaker
Copy link
Member

0.7.8 is out!

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.

3 participants