Open
Conversation
1b05d65 to
f8fa58c
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #656 +/- ##
==========================================
- Coverage 88.28% 88.20% -0.08%
==========================================
Files 21 21
Lines 751 975 +224
Branches 123 167 +44
==========================================
+ Hits 663 860 +197
- Misses 62 80 +18
- Partials 26 35 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
This PR implements comprehensive asynchronous support for django-constance, making configuration access seamless and efficient in both sync and async Django environments.
Why?
Previously, using Constance in an async context (like a Django async def view) was problematic:
await sync_to_async(lambda: config.KEY)(), which is verbose and prone to errors.This implementation removes these barriers by making the config object "async-agnostic"—it detects the execution context and provides the correct, non-blocking path automatically.
How to Use
In an async view or function, you can now simply await any configuration key:
New native async methods have been added for updates and batch operations:
If you forget to use await inside an async loop, the app will still work (to prevent crashes), but it will:
await sync_to_async(lambda: config.KEY)()will continue to work without any issues or drawbacks. Dropping the sync_to_async-lambda combination will increase performance or at the very least developer experience though.Key Technical Changes
Verification