InMemoryBackingStore infinite loop
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Comece localizando a classe InMemoryBackingStore e inspecionando seu método set, especialmente a assinatura adicionada para valores BackedModel e listas. Reproduza o problema com um BackedModel ou uma lista de instâncias de BackedModel e rastreie as notificações dos assinantes. Está concluído quando definir o valor o armazena e notifica os assinantes sem invocar set recursivamente nem entrar em um loop infinito.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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_
- Linguagem predominante
- Python
- Estrelas
- 630
- Forks
- 96
- Merge médio
- 15h 20min
- PRs com merge (30d)
- 3
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoftgraph/msgraph-sdk-python
-
status:waiting-for-triage type:bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
microsoftgraph/msgraph-sdk-python#1570 ·
-
status:waiting-for-triage type:bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
microsoftgraph/msgraph-sdk-python#1563 ·
-
Needs: Attention :wave: type:bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
microsoftgraph/msgraph-sdk-python#1287 · 2 comentários · 1 reação ·
-
Batch Request Support Abertastatus:waiting-for-triage
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
microsoftgraph/msgraph-sdk-python#1557 ·
-
status:waiting-for-triage type:bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
microsoftgraph/msgraph-sdk-python#1556 · 1 comentário · 1 reação ·
Todas as issues de microsoftgraph/msgraph-sdk-python
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
zostera/django-bootstrap4#894 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
use-agent-os/agent-os#3276 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
NousResearch/hermes-agent#117848 ·