aws / aws/sagemaker-python-sdk

Importing sagemaker seems to enable rich tracebacks

オープン
#5,179 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る
component: debugger component: pysdk-team type: bug
主要言語
Python
スター
2.3k
フォーク
1.3k
平均マージ
1日 22時間
マージ済み PR(30日)
35

説明

**Describe the bug**

Whenever sagemaker is imported, it seems to modify and automatically enable [rich](https://github.com/Textualize/rich) tracebacks.

**To reproduce**

Make a new environment

```console
$ python -m venv .venv
$ source /.venv/bin/activate
$ python -m pip install sagemaker rich
```

Make a file that returns a traceback

```python
"""rich_sage.py"""
import sagemaker

def main() -> None:
raise ValueError

if __name__ == "__main__":
main()

```

Run the file

```console
$ python rich_sage.py
sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml
sagemaker.config INFO - Not applying SDK defaults from location: /Users/pawlu/Library/Application Support/sagemaker/config.yaml
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/pawlu/Documents/scratch/rich_sage/sage_me.py:9 in │
│ │
│ 6 │
│ 7 │
│ 8 if __name__ == "__main__": │
│ ❱ 9 │ main() │
│ 10 │
│ │
│ /Users/pawlu/Documents/scratch/rich_sage/sage_me.py:5 in main │
│ │
│ 2 │
│ 3 │
│ 4 def main() -> None: │
│ ❱ 5 │ raise ValueError │
│ 6 │
│ 7 │
│ 8 if __name__ == "__main__": │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError
```

If the import statement is removed,

```diff
- import sagemaker
```

then the traceback renders as expected

```console
$ python rich_sage.py
Traceback (most recent call last):
File "/Users/pawlu/Documents/scratch/rich_sage/sage_me.py", line 8, in
main()
File "/Users/pawlu/Documents/scratch/rich_sage/sage_me.py", line 4, in main
raise ValueError
ValueError
```

**Expected behavior**

Ideally, tracebacks shouldn't be modified without users input. At worst there should be a way to opt out of this. But we shouldn't be modifying tracebacks automatically at import. It's a tricky behavior that's hard to debug.

**Screenshots or logs**

Image

**System information**
A description of your system. Please provide:
- **SageMaker Python SDK version**: 2.244.0
- **Framework name (eg. PyTorch) or algorithm (eg. KMeans)**: Rich
- **Framework version**: 14.0.0
- **Python version**: 3.12.9
- **CPU or GPU**: M3 (macbook)
- **Custom Docker image (Y/N)**: N

---

Thank you very much!

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

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

調査の方向性

報告されている SageMaker と Rich のバージョンを使って rich_sage.py の再現を実行し、import sagemaker の有無で traceback の出力を比較します。SageMaker パッケージ内の import による副作用を追跡し、ユーザーの操作なしに SageMaker を import しても Rich の traceback が有効にならないことを確認します。

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

評価

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

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

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