fix: race condition в LazyRef.fetch() и __bool__ для pending ref#102
Closed
bish-x wants to merge 0 commit intolove-apples:feat/fetch-without-auto-requestsfrom
Closed
fix: race condition в LazyRef.fetch() и __bool__ для pending ref#102bish-x wants to merge 0 commit intolove-apples:feat/fetch-without-auto-requestsfrom
bish-x wants to merge 0 commit intolove-apples:feat/fetch-without-auto-requestsfrom
Conversation
8ee6b36 to
2ed5651
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Описание
Два исправления для механизма lazy ref из PR #101.
1. Race condition в
LazyRef.fetch()При параллельных вызовах
fetch()(например,asyncio.gather(event.fetch_chat(), event.fetch_from_user())) оба вызова видели_resolved is _UNSETи оба выполняли API-запрос. Результат — дублирование запросов и двойной вызов setter.Добавлен
asyncio.Lockдля сериализации — первый вызов загружает и кеширует, остальные получают кешированный результат.2.
__bool__для pending LazyRefРанее
bool(pending_ref)возвращалFalse. Это приводило к тому, что паттерн из документации не работал:Теперь pending ref =
True(ref существует, данные доступны черезfetch()). После resolve:bool(resolved_value).Тесты
Добавлен
tests/test_fetchable.py— 11 тестов:__bool__для pending / resolved None / resolved value__getattr__proxy и AttributeError до fetch__repr__для pending и resolvedВсе существующие тесты проходят без изменений.