Open
Labels
engineer-botMaintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).
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)Metadata
Metadata
Assignees
Labels
engineer-botMaintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).
Activity
kravets-levko commentedon Sep 10, 2024
@chidifrank thank you for reporting this! May I ask you to share a stacktrace for this error so I can understand where it comes from? None of that errors should be raised without a message, so your case indicates that something is wrong elsewhere
chidifrank commentedon Sep 10, 2024
@kravets-levko
Sure!
kravets-levko commentedon Sep 10, 2024
Thank you! Yeah, looks that it is initialized with the error message from server, but it actually may be empty. We need additional check there, as well as a reasonable fallback (probably)
chidifrank commentedon Sep 10, 2024
Thanks for the effort! @kravets-levko
peco-engineer-bot commentedon Jul 23, 2026
🤖 engineer-bot opened a fix PR: #875
Review before merge.