fix: yield form in fastui_form to keep file handler open#170
fix: yield form in fastui_form to keep file handler open#170gradient-ascent-ai-lab wants to merge 3 commits intopydantic:mainfrom
Conversation
samuelcolvin
left a comment
There was a problem hiding this comment.
Thanks so much. Please fix tests and and some more tests that would fail without this.
|
Glad to hear the contribution is appreciated! I'd love to fix the tests and add more, but looking deeper into the issue I am not sure my fix is the correct approach, as it requires changing all lines with I find my mental model of the control flow through the layers of FastUI/FastAPI/Starlette (especially with classes like Starlette's |
|
Well the tests having odd syntax isn't the end of the world as long as real world cases are handled correctly and elegantly. I think the solution might be as simple as adding |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #170 +/- ##
==========================================
+ Coverage 94.30% 94.31% +0.01%
==========================================
Files 11 11
Lines 755 757 +2
==========================================
+ Hits 712 714 +2
Misses 43 43 ☔ View full report in Codecov by Sentry. |
1d0f15d to
e6ccc96
Compare
|
Thanks for the guidance! |
|
@samuelcolvin Any progress on this ? |
|
I've run into this issue myself. Is this PR going to make it to master or is there another better fix? |
|
@sydney-runkle / @samuelcolvin, seems like this PR is ready to be merged and would be |
I ran into the same issue as #146, where in all cases the file handler of an UploadFile is already closed when it becomes available in the endpoint function. I found where the closing of a context manager leads to the closing of the filehandler, and found that yielding inside the
request.form()context instead of returning after it fixes it. I'm not sure if this is the ideal solution (probably not as CI is breaking on the typechecker) but at least it's pretty minimal and fixes the issue, so I thought it useful enough to share.