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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/snowflake/connector/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ def execute(
"errno": int(code),
"sqlstate": self._sqlstate,
"sfqid": self._sfqid,
"query": query,
}
is_integrity_error = (
code == "100072"
Expand Down
7 changes: 5 additions & 2 deletions src/snowflake/connector/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
errno: int | None = None,
sqlstate: str | None = None,
sfqid: str | None = None,
query: str | None = None,
done_format_msg: bool | None = None,
connection: SnowflakeConnection | None = None,
cursor: SnowflakeCursor | None = None,
Expand All @@ -48,6 +49,7 @@ def __init__(
self.errno = errno or -1
self.sqlstate = sqlstate or "n/a"
self.sfqid = sfqid
self.query = query

if self.msg:
# TODO: If there's a message then check to see if errno (and maybe sqlstate)
Expand All @@ -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.query}: {self.msg}"
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.

else:
if not already_formatted_msg:
if logger.getEffectiveLevel() in (logging.INFO, logging.DEBUG):
Expand Down Expand Up @@ -221,6 +223,7 @@ def default_errorhandler(
errno=None if errno is None else int(errno),
sqlstate=error_value.get("sqlstate"),
sfqid=error_value.get("sfqid"),
query=error_value.get("query"),
done_format_msg=(
None if done_format_msg is None else bool(done_format_msg)
),
Expand Down
4 changes: 3 additions & 1 deletion test/unit/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

def test_detecting_duplicate_detail_insertion():
sfqid = str(uuid.uuid4())
query = "select something_really_buggy from buggy_table"
sqlstate = "24000"
errno = 123456
msg = "Some error happened"
expected_msg = re.compile(rf"{errno} \({sqlstate}\): {sfqid}: {msg}")
expected_msg = re.compile(rf"{errno} \({sqlstate}\): {sfqid}: {query}: {msg}")
original_ex = errors.ProgrammingError(
sqlstate=sqlstate,
sfqid=sfqid,
query=query,
errno=errno,
msg=msg,
)
Expand Down