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

SNOW-701257: add query attribute to Error class #1437

Merged
merged 6 commits into from
Feb 22, 2023

Conversation

sfc-gh-aalam
Copy link
Collaborator

@sfc-gh-aalam sfc-gh-aalam commented Feb 14, 2023

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes #SNOW-701257

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Adding query in ProgrammingError so that query information is not lost if logging is unset. Related PR SNOW-701257: optionally disable logging error for sql exceptions snowpark-python#674

@sfc-gh-aalam sfc-gh-aalam marked this pull request as ready for review February 15, 2023 15:44
@sfc-gh-aalam sfc-gh-aalam requested review from sfc-gh-yixie, sfc-gh-jdu and a team February 15, 2023 15:44
@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2023

Codecov Report

Merging #1437 (189e739) into main (1d3d87e) will increase coverage by 0.06%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main    #1437      +/-   ##
==========================================
+ Coverage   81.77%   81.83%   +0.06%     
==========================================
  Files          60       60              
  Lines        8575     8577       +2     
  Branches     1266     1266              
==========================================
+ Hits         7012     7019       +7     
+ Misses       1236     1232       -4     
+ Partials      327      326       -1     
Impacted Files Coverage Δ
src/snowflake/connector/cursor.py 94.66% <ø> (ø)
src/snowflake/connector/errors.py 89.94% <66.66%> (-0.48%) ⬇️
src/snowflake/connector/ocsp_asn1crypto.py 79.54% <0.00%> (-0.91%) ⬇️
src/snowflake/connector/ocsp_snowflake.py 78.40% <0.00%> (+1.07%) ⬆️
src/snowflake/connector/test_util.py 56.25% <0.00%> (+2.91%) ⬆️

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

Copy link
Contributor

@sfc-gh-sfan sfc-gh-sfan left a comment

Choose a reason for hiding this comment

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

LGTM

@sfc-gh-sfan
Copy link
Contributor

You might want to port it to sp connector as well. Should be simple.

else:
self.msg = f"{self.errno:06d} ({self.sqlstate}): {self.msg}"
self.msg = f"{self.errno:06d} ({self.sqlstate}): {self.query}: {self.msg}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure about this section. Should we add query here even when we were not printing sfqid

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also think we should add sfqid. I don't know why we should hide them at WARN and ERROR level. That means user's production long won't have them.
But @sfc-gh-mkeller once mentioned that this should be regarded as a break change.

@@ -66,9 +68,9 @@ def __init__(
if self.sqlstate != "n/a":
if not already_formatted_msg:
if logger.getEffectiveLevel() in (logging.INFO, logging.DEBUG):
self.msg = f"{self.errno:06d} ({self.sqlstate}): {self.sfqid}: {self.msg}"
self.msg = f"{self.errno:06d} ({self.sqlstate}): {self.sfqid}: {self.msg}: {self.query}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sfc-gh-mkeller could I get your input on whether this could be considered behavior change? We want to add query into Errors generated by python connector (more context here) so that query is easily accessible when debugging issues and does not get lost.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, I don't think that this would be a behavior change, but I think it should be.
If you look at line 46 super().__init__(msg) you'll see that we call Exceptions's initalizer with the initially given msg, so this later isn't a behavior change. But I'm not sure that right now it works as it should. I verified this with:

❯ python
Python 3.9.16 (main, Dec  7 2022, 10:06:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from snowflake.connector.errors import Error
/Users/mkeller/snowflakedb/snowflake-connector-python/src/snowflake/connector/options.py:13: UserWarning: Module snowflake was already imported from None, but /Users/mkeller/snowflakedb/snowflake-connector-python/src is being added to sys.path
  import pkg_resources
>>> e = Error("this is a test error", errno=111)
>>> e.args
('this is a test error',)
>>> e.msg
'000111: this is a test error'

Copy link
Collaborator

Choose a reason for hiding this comment

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

However; it does affect __str__

>>> str(e)
'000111: this is a test error'

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a middle ground could we not add the query to msg but have it as a field of Error? For the short-term at least

@sfc-gh-aalam sfc-gh-aalam enabled auto-merge (squash) February 22, 2023 07:06
@sfc-gh-aalam sfc-gh-aalam merged commit ea7fc66 into main Feb 22, 2023
@sfc-gh-aalam sfc-gh-aalam deleted the aalam-SNOW-701257-add-query-in-Error branch February 22, 2023 07:08
@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2023
@sfc-gh-aalam
Copy link
Collaborator Author

You might want to port it to sp connector as well. Should be simple.

https://github.com/snowflakedb/Stored-Proc-Python-Connector/pull/87

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants