Skip to content

Bug in databricks.sql.exc.Error base class #437

Description

@chidifrank

Problem: When try except catching errors and logging them I occasionally get this TypeError

...
try:
withconnection.cursor() ascursor:
cursor.execute(query)
...
exceptdatabricks.sql.Errorase:
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

classError(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=messageself.context=contextor {}
def__str__(self):
returnself.messagedefmessage_with_context(self):
returnself.message+": "+json.dumps(self.context, default=str)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions