Added async support #656
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 360 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #656"
general
weight: 0.35
Mogost
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:
1. Thread Blocking: Accessing config.KEY synchronously inside an async view blocks the event loop, negating the performance benefits of async.
2. Database Errors: For the Database backend, Django's safety guards would raise a SynchronousOnlyOperation error because database queries are prohibited on the main async thread.
3. Manual Overhead: Developers had to manually wrap every Constance access in
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
1. Simple Async Access
In an async view or function, you can now simply await any configuration key:
``
python
`async def my_view(request):
# Non-blocking async retrieval
if await config.MY_SETTING:
...
python
Update a setting asynchronously
await config.aset('MY_SETTING', 'new_value')
Fetch multiple settings in one non-blocking call
values = await config.amget(['SETTING_A', 'SETTING_B'])
3. Gradual Migration & Safety Guards
If you forget to use await inside an async loop, the app will still work (to prevent crashes), but it will:
Key Technical Changes
- DatabaseBackend now uses afirst() and afetch() for non-blocking I/O.
- RedisBackend leverages redis.asyncio for native speed.
Verification