async function support in url_defaults and url_value_preprocessor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
Description
currently if you try to use an async function in url_defaults or url_value_preprocessor it raises
.venv/lib/python3.10/site-packages/quart/app.py:1450: RuntimeWarning: coroutine 'pull_lang_code' was never awaited
error.
The following code uses get_preferred_language from Quart-Babel extension but it could also be an async db call in an url_value_preprocessor function.
@app.url_defaults
async def add_language_code(endpoint, values):
if app.url_map.is_endpoint_expecting(endpoint, "lang_code"):
prefered_lang = await get_preferred_language()
values.setdefault("lang_code", prefered_lang)
do you have any workaround/suggestions to this situation?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading quart/app.py around line 1450 and trace how url_defaults and url_value_preprocessor callbacks are invoked. Check how coroutine results are handled and whether related routing entry points are involved. Done means async callbacks can await get_preferred_language without a RuntimeWarning while synchronous callbacks continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100