InMemoryBackingStore infinite loop
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Beginne damit, die Klasse InMemoryBackingStore zu lokalisieren und ihre set-Methode zu untersuchen, insbesondere das für BackedModel-Werte und Listen hinzugefügte Abonnement. Reproduziere das Problem mit einem BackedModel oder einer Liste von BackedModel-Instanzen und verfolge die Benachrichtigungen der Abonnenten. Als erledigt gilt die Aufgabe, wenn das Setzen des Werts ihn speichert und die Abonnenten benachrichtigt, ohne set rekursiv aufzurufen oder in eine Endlosschleife zu geraten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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_
- Vorherrschende Sprache
- Python
- Sterne
- 630
- Forks
- 96
- Ø Merge
- 15 Std. 20 Min.
- Gemergte PRs (30 T.)
- 3
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoftgraph/msgraph-sdk-python
-
status:waiting-for-triage type:bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
microsoftgraph/msgraph-sdk-python#1570 ·
-
status:waiting-for-triage type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
microsoftgraph/msgraph-sdk-python#1563 ·
-
Needs: Attention :wave: type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
microsoftgraph/msgraph-sdk-python#1287 · 2 Kommentare · 1 Reaktion ·
-
Batch Request Support Offenstatus:waiting-for-triage
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
microsoftgraph/msgraph-sdk-python#1557 ·
-
status:waiting-for-triage type:bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
microsoftgraph/msgraph-sdk-python#1556 · 1 Kommentar · 1 Reaktion ·
Alle Issues in microsoftgraph/msgraph-sdk-python
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
zostera/django-bootstrap4#894 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
use-agent-os/agent-os#3276 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·