Accept the use of async predict methods #1565
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the issue when a request has the content type set to
multipart/form-data
and a file is uploaded (i.e. when making a request of this kindcurl <api-endpoint> -X POST -H "Content-Type: multipart/form-data" -F "iris=@sample.json"
).This is because reading a form file requires the call of an async method
read
, which cannot be called unless thepredict
method of the predictor is an async method too, which in turn, means, the backend method must be an async function as well.Here's an example of how to read a file using forms (scroll to the bottom of the page): https://www.starlette.io/requests/.
Edit
This is no longer required because the file can just be retrieved from the
payload.file
attribute, which is already a tempfile.SpooledTemporaryFile object. As shown in #1566. That being said, this PR might still be of interest to those that use async functions.checklist:
make test
andmake lint