Positional-only task parameters that a dependency supplies fail at call time

Aperta
#593 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start by tracing dependency resolution and the worker call path that invokes tasks with **kwargs; the issue does not name specific files or tests. Reproduce with the positional-only examples in the issue, including the Annotated form, then choose whether resolved values are passed positionally or registration rejects these parameters. Done when both forms either execute correctly or fail at registration with a clear error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When a dependency supplies a positional-only parameter, the worker passes the resolved value as a keyword argument, and Python rejects the call:

async def task(customer_id: int, db: str = Depends(get_db), /) -> None: ...

await docket.add(task)(1)
TypeError: task() got some positional-only arguments passed as keyword arguments: 'db'

The same happens with the Annotated form from #591, async def task(db: Annotated[str, Depends(get_db)], /), because resolution returns every dependency-supplied value by name and the worker calls the task with **kwargs.

Two ways to handle it: pass resolved positional-only values positionally when the worker calls the task, or reject a positional-only dependency parameter with a clear error when the task is registered. Positional-only task parameters are rare, so either is reasonable.

Found in review of #591.

Lingua principale
Python
Stelle
148
Fork
12
Merge medio
15h 49m
PR unite (30g)
45

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di chrisguidry/docket

Tutte le issue di chrisguidry/docket

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.