Skip to content

Added the ability to transfer Pydantic model to FormData#2139

Closed
vobinics wants to merge 2 commits into
fastapi:masterfrom
vobinics:master
Closed

Added the ability to transfer Pydantic model to FormData#2139
vobinics wants to merge 2 commits into
fastapi:masterfrom
vobinics:master

Conversation

@vobinics

@vobinics vobinics commented Oct 6, 2020

Copy link
Copy Markdown

Fixed error 422 when creating Pydantic model from FormData. Example temporal workaround on StackOverflow

@codecov

codecov Bot commented Oct 6, 2020

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e77ea63) 100.00% compared to head (e6ec56d) 100.00%.
Report is 2321 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2139   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          239       240    +1     
  Lines         7079      7104   +25     
=========================================
+ Hits          7079      7104   +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Oct 6, 2020

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit e6ec56d at: https://5f7cddf0dd4b3c014cae6e71--fastapi.netlify.app

@Fkawala

Fkawala commented Jul 12, 2021

Copy link
Copy Markdown

Hey, I'd be interest to have this merged, is there anything blocking this to be merged ? Thank you !

@iudeen

iudeen commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

I tried


from fastapi import FastAPI, Form, Depends, UploadFile
from pydantic import BaseModel

app = FastAPI()


class SimpleModel(BaseModel):
    no: int = Form(...)
    nm: str = Form(...)
    f: UploadFile = Form(...)


@app.post("/form")
async def form_post(form_data: SimpleModel = Depends()):
    fp = await form_data.f.read()
    print(fp)

It works with current (0.86) version. Is this PR still needed?

@tiangolo tiangolo added the feature New feature or request label Oct 2, 2023
@tiangolo tiangolo added p4 and removed investigate labels Jan 15, 2024
@tiangolo

tiangolo commented Sep 8, 2024

Copy link
Copy Markdown
Member

Thanks! ☕

This was covered in #12129, it is available in FastAPI 0.113.0 🎉

The new docs: https://fastapi.tiangolo.com/tutorial/request-form-models/

Given that, I'll close this one, but thanks for the effort! 🍰

@tiangolo tiangolo closed this Sep 8, 2024
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Files with missing lines Coverage Δ
fastapi/dependencies/utils.py 100.00% <100.00%> (ø)
tests/test_pydantic_model_in_form.py 100.00% <100.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request p4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants