Bug in `databricks.sql.exc.Error` base class

オープン 初心者向け
#437 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
databases

調査の方向性

コネクタで databricks.sql.exc.Error クラスを検索し、その str メソッドと message_with_context メソッドを調べます。メッセージなしの Error を再現し、その後、文字列変換と message_with_context が失敗しなくなっていること、および既存のエラー動作が維持されていることを確認します。

索引モデルが issue の本文から書いたものです。

説明

engineer-bot

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)
主要言語
Python
スター
233
フォーク
152
平均マージ
21時間 5分
マージ済み PR(30日)
10

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

databricks/databricks-sql-python のほかの issue

databricks/databricks-sql-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。