Bug in databricks.sql.exc.Error base class (#437)#875
Open
peco-engineer-bot[bot] wants to merge 1 commit into
Open
Bug in databricks.sql.exc.Error base class (#437)#875peco-engineer-bot[bot] wants to merge 1 commit into
databricks.sql.exc.Error base class (#437)#875peco-engineer-bot[bot] wants to merge 1 commit into
Conversation
Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automated fix for #437 — Bug in
databricks.sql.exc.Errorbase class.In src/databricks/sql/exc.py, Error.str now returns
self.message or ""(guaranteeing a str per Python's object.str contract cited in the issue) and message_with_context computes(self.message or "") + ": " + json.dumps(self.context, default=str), so a None message no longer raisesTypeError: __str__ returned non-stringorunsupported operand type(s) for +: 'NoneType' and 'str'. Both unit tests pass. This is a client-side exception-formatting artifact anchored in the Python data model (not end-to-end observable against a warehouse), so unit tests satisfy the offline carve-out.Root cause & plan
Root cause: In src/databricks/sql/exc.py, the Error base class stores self.message = message (default None).
__str__returns self.message directly, so when message is None Python raisesTypeError: __str__ returned non-string (type NoneType). Separately,message_with_contextcomputesself.message + ": " + json.dumps(...), which raisesTypeError: unsupported operand type(s) for +: 'NoneType' and 'str'when message is None. Both need to coerce/guard a None message. Correctness anchored in the Python data model (object.str must return a string), cited by the issue — a client-side artifact, not warehouse-observable, so unit tests satisfy the carve-out.Files:
src/databricks/sql/exc.py,tests/unit/test_exc.pyPlanned coverage:
Files changed
tests/unit/test_exc.pysrc/databricks/sql/exc.pyTest plan
tests/unit/test_exc.py::TestError::test_str_returns_string_when_message_is_none— fails (red) against the original code, passes (green) after the fixtests/unit/test_exc.py::TestError::test_message_with_context_when_message_is_none— fails (red) against the original code, passes (green) after the fix🤖 Generated by engineer-bot (bug-fix flow) — review before merge.