microsoftgraph / microsoftgraph/msgraph-sdk-python
InMemoryBackingStore infinite loop
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 630
- フォーク
- 96
- 平均マージ
- 15時間 20分
- マージ済み PR(30日)
- 3
説明
Describe the bug
The InMemoryBackingStore class is experiencing an infinite loop when setting values. This occurs because the set method subscribes a lambda function that calls set again, which in turn triggers the subscription callback, causing set to be called repeatedly.
if isinstance(value, list):
# if its a collection, subscribe to the collection's item BackingStores and use
# the events to flag the collection property is "dirty"
for item in value:
if isinstance(item, BackedModel) and item.backing_store:
item.backing_store.is_initialization_completed = True
item.backing_store.subscribe(
lambda prop_key, old_val, new_val: self.set(key, value)
)
self.__store[key] = value_to_add
for sub in list(self.__subscriptions):
self.__subscriptions[sub](key, old_value, value_to_add)
Because you're invoking the subscription which is calling set which is invoking the subscription.
Expected behavior
The set method should store the value and notify subscribers without causing an infinite loop.
How to reproduce
- Create an instance of InMemoryBackingStore.
- Set a value that is a BackedModel or a list containing BackedModel instances.
- The set method subscribes a lambda function that calls set again.
- The subscription callback is triggered, causing set to be called repeatedly.
SDK Version
No response
Latest version known to work for scenario above?
No response
Known Workarounds
Awful, but until an update, unsubscribing and re-subscribing around problematic code.
subscription_ids = []
# Collect all backing stores and sub ids as to not modify while iterating
for role in app.app_roles:
if isinstance(role, BackedModel) and role.backing_store:
for (
sub_id,
callback,
) in role.backing_store._InMemoryBackingStore__subscriptions.items():
if callback.__name__ == "<lambda>":
subscription_ids.append((role.backing_store, sub_id))
# Unsubscribe lambdas...
for backing_store, sub_id in subscription_ids:
backing_store.unsubscribe(sub_id)
# Problematic code
for role in app.app_roles:
if role.is_enabled != enable:
role.is_enabled = enable
# Resubscribe lambdas...
for backing_store, sub_id in subscription_ids:
backing_store.subscribe(
lambda prop_key, old_val, new_val: role.backing_store.set(
prop_key, new_val
),
sub_id,
)
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず InMemoryBackingStore クラスを見つけて、その set メソッドを調べます。特に、BackedModel 値とリストに追加されたサブスクリプションを確認してください。BackedModel または BackedModel インスタンスのリストを使って問題を再現し、サブスクライバーへの通知を追跡します。値を設定するとその値が保存され、set を再帰的に呼び出したり無限ループに入ったりせずにサブスクライバーへ通知されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100