Skip to content

fix: 🐛 Protecting concurrent cache access with async recipes#221

Merged
remimd merged 1 commit intodevfrom
concurrency
Mar 30, 2025
Merged

fix: 🐛 Protecting concurrent cache access with async recipes#221
remimd merged 1 commit intodevfrom
concurrency

Conversation

@remimd
Copy link
Copy Markdown
Member

@remimd remimd commented Mar 30, 2025

No description provided.

@remimd remimd self-assigned this Mar 30, 2025
@remimd remimd requested a review from Copilot March 30, 2025 14:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a bug in concurrent cache access by introducing async recipes and improving slot handling during injection. It also refines caching logic in injectables, enhances scope error handling, and adds a new test case to verify the injection error when a slot is set multiple times.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/core/test_module.py Added a test to verify that setting a slot twice raises InjectionError.
pyproject.toml Added anyio as a development dependency.
injection/_core/slots.py Modified ScopedSlot.set to use the setdefault method for instance assignment.
injection/_core/scope.py Enhanced scope lookup functions to safely handle undefined states.
injection/_core/module.py Wrapped asynchronous instance retrieval with suppress(SkipInjectable).
injection/_core/injectables.py Refactored caching logic with new CachedInjectable and updated SingletonInjectable/ScopedInjectable.
injection/_core/common/asynchronous.py Reworked semaphore creation to use anyio when available.
Comments suppressed due to low confidence (1)

injection/_core/slots.py:23

  • [nitpick] Consider documenting or renaming the 'setdefault' method in ScopedInjectable to clearly differentiate its behavior from the standard dict.setdefault. This will help maintainers understand that it is used for controlled instance caching.
if self.injectable.setdefault(instance) is not instance:

@remimd remimd merged commit 3709268 into dev Mar 30, 2025
5 checks passed
@remimd remimd deleted the concurrency branch March 30, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants