Bug in `databricks.sql.exc.Error` base class
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Search the connector for the databricks.sql.exc.Error class and inspect its str and message_with_context methods. Reproduce an Error with no message, then verify that string conversion and message_with_context no longer fail and that existing error behavior remains intact.
Written by the indexing model from the issue text.
Description
Problem: When try except catching errors and logging them I occasionally get this TypeError
...
try:
with connection.cursor() as cursor:
cursor.execute(query)
...
except databricks.sql.Error as e:
logger.debug(f"{str(e)}: failed to execute query {query}")
...
__str__ returned non-string (type NoneType)
Explanation:
String representations of a class must be of type string
the message attribute can be None therefore there needs to be a check/cast prior to returning.
Note: message_with_context will also fail when a message is None since you can't use the operand type + for NoneType and a str
class Error(Exception):
"""Base class for DB-API2.0 exceptions.
`message`: An optional user-friendly error message. It should be short, actionable and stable
`context`: Optional extra context about the error. MUST be JSON serializable
"""
def __init__(self, message=None, context=None, *args, **kwargs):
super().__init__(message, *args, **kwargs)
self.message = message
self.context = context or {}
def __str__(self):
return self.message
def message_with_context(self):
return self.message + ": " + json.dumps(self.context, default=str)
- Dominant language
- Python
- Stars
- 233
- Forks
- 152
- Avg merge
- 21h 5m
- Merged PRs (30d)
- 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databricks/databricks-sql-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
All issues in databricks/databricks-sql-python
Similar issues
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
modelscope/DiffSynth-Studio#1702 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenHands/extensions#626 · 1 comment ·