Skip to content

Bug in databricks.sql.exc.Error base class (#437)#875

Open
peco-engineer-bot[bot] wants to merge 1 commit into
mainfrom
ai/issue-437
Open

Bug in databricks.sql.exc.Error base class (#437)#875
peco-engineer-bot[bot] wants to merge 1 commit into
mainfrom
ai/issue-437

Conversation

@peco-engineer-bot

Copy link
Copy Markdown
Contributor

Summary

Automated fix for #437 — Bug in databricks.sql.exc.Error base 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 raises TypeError: __str__ returned non-string or unsupported 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 raises TypeError: __str__ returned non-string (type NoneType). Separately, message_with_context computes self.message + ": " + json.dumps(...), which raises TypeError: 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.py
Planned coverage:

  • Construct databricks.sql.exc.Error() with no message and assert str(e) returns a string (e.g. '') without raising TypeError — verifies str never returns non-string. (str returns None when message is None)
  • Construct Error(context={...}) with message=None and assert message_with_context() returns a string containing the JSON-serialized context without raising TypeError. (message_with_context raises on None + str when message is None)

Files changed

  • tests/unit/test_exc.py
  • src/databricks/sql/exc.py

Test 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 fix
  • tests/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.

Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>
@peco-engineer-bot peco-engineer-bot Bot added the engineer-bot Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR). label Jul 23, 2026

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engineer-bot Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants