Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Cloudpickle does not properly register submodule dependencies of a pickled function if the function accesses the submodule via `getattr` (or equivalent means)

オープン
#581 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

cloudpickle/cloudpickle.py の 383 行付近にあるサブモジュール検出ロジックから始め、次に報告にある getattr または vars(concurrent)['futures'] の例で問題を再現してください。pickling 中に名前がどのように収集されるかを追跡し、サブモジュール名に間接的にアクセスした場合に、dump された関数を別のセッションでロードして正常に呼び出せることを確認してください。

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

説明

As seen on master:

>>> import cloudpickle
>>> cloudpickle.version
'3.2.0.dev0'
>>> import concurrent.futures
>>> def func():                                              
...     x = getattr(concurrent, 'futures').ThreadPoolExecutor
... 
>>> func()  # can be succesfully called
>>> cloudpickle.dump(func, open('/tmp/dump', 'wb'))

Then in another session:

>>> import cloudpickle
>>> cloudpickle.load(open('/tmp/dump', 'rb'))()  # not callable upon load
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in func
AttributeError: module 'concurrent' has no attribute 'futures'

The reason is that at pickle time, the submodule detection logic only registers that a function needs a submodule x.y.z if the strings y, z all appear in the set of names stored in the function's code object. If the pickled function were to access the submodule via concurrent.futures, then both concurrent and futures appear in the set of names. But in the failing example above, 'futures' is a string and so doesn't appear in the set of names.

We can trigger the failure by replacing the getattr call with say vars(concurrent)['futures'] or concurrent.__dict__['futures'] for the same reason.

Relates to this issue about slow performance when pickling functions that use packages.

One could argue that this access pattern is sufficiently abnormal that cloudpickle doesn't need to handle it properly. But in the related issue, a maintainer asked me to make a new issue for this problem.

主要言語
Python
スター
1.9k
フォーク
197
平均マージ
1日 10時間
マージ済み PR(30日)
1

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

cloudpipe/cloudpickle のほかの issue

cloudpipe/cloudpickle の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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