Skip to content

AssertionError with multiple path params and form depends #7745

Answered by tiangolo
pozsa asked this question in Questions
Discussion options

You must be logged in to vote

You are declaring the same name date in 2 places, a path parameter and a form.

Consider them all as parameters of the same function, even if they are in a dependency, so one of them ends up overwriting the other.

You can change the form date to be named date_form, and then use an alias to make the form field still be date:

from typing import Union, Optional
import datetime
from fastapi import FastAPI
import fastapi

app = FastAPI()

class DocumentUpdateForm():
    def __init__(
            self,
            date_form: datetime.date = fastapi.Form(..., alias="date"),
            file_object: Optional[fastapi.UploadFile] = fastapi.File(None),
            name: str = fastapi.Form(...),
     …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by pozsa
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
2 participants
Converted from issue

This discussion was converted from issue #926 on February 28, 2023 10:50.