Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Validation of optional sequence in multipart data with one value #3408

Merged
merged 5 commits into from
Apr 29, 2024

Conversation

provinzkraut
Copy link
Member

Fix #3407.

A Sequence[UploadFile] | None would not pass validation when a single value was provided for a structured type, e.g. dataclass.

@provinzkraut provinzkraut requested review from a team as code owners April 20, 2024 10:11
@github-actions github-actions bot added area/kwargs area/private-api This PR involves changes to the privatized API size: small type/bug pr/internal labels Apr 20, 2024
Copy link

codecov bot commented Apr 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.29%. Comparing base (c625ce7) to head (85236f9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3408   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files         328      328           
  Lines       14864    14865    +1     
  Branches     2358     2358           
=======================================
+ Hits        14610    14611    +1     
  Misses        116      116           
  Partials      138      138           

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

@provinzkraut provinzkraut force-pushed the fix-optional-list-multipart-data branch from 354094f to 1eac15a Compare April 20, 2024 10:22
Copy link
Member

@guacs guacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the case where the annotation is directly on the handler itself also needs to be handled. I don't think there's a test for it.

def handler(data: list[UploadFile] | None): ...

@provinzkraut
Copy link
Member Author

I think that one is already handled but I haven't actually checked it, I assumed we were testing that already. Can't check right now as I'm on the road but I'll do once I'm back home.

@peterschutt
Copy link
Contributor

I think the case where the annotation is directly on the handler itself also needs to be handled. I don't think there's a test for it.

def handler(data: list[UploadFile] | None): ...

There does seem to be an issue with this too, but its failing when there are 2 or more files provided.

@peterschutt
Copy link
Contributor

I think the case where the annotation is directly on the handler itself also needs to be handled. I don't think there's a test for it.

def handler(data: list[UploadFile] | None): ...

There does seem to be an issue with this too, but its failing when there are 2 or more files provided.

Created #3409 and #3410 for this

Copy link
Member

@guacs guacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment can be ignored since another issue for that case was created. LGTM!

@provinzkraut
Copy link
Member Author

My comment can be ignored since another issue for that case was created. LGTM!

Oops. I fixed it here before that PR was created 😬
@peterschutt Should I revert?

@peterschutt
Copy link
Contributor

My comment can be ignored since another issue for that case was created. LGTM!

Oops. I fixed it here before that PR was created 😬 @peterschutt Should I revert?

No, I'm happy for it to go though here.

@euri10
Copy link
Contributor

euri10 commented Apr 29, 2024

@provinzkraut I think we can safely ignore reportGeneralTypeIssues line 405 of multipart, merge this and close @peterschutt competing one, wdyt ?

@peterschutt
Copy link
Contributor

@euri10 #3410 already closed, superseded by this. We should probably tag this as closing #3409 so it closes when it goes through.

@provinzkraut
Copy link
Member Author

@provinzkraut I think we can safely ignore reportGeneralTypeIssues line 405 of multipart, merge this and close @peterschutt competing one, wdyt ?

Don't have time rn to do this but if you want, feel free to take this on.

Copy link

sonarcloud bot commented Apr 29, 2024

Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3408

@euri10 euri10 merged commit b9e501f into main Apr 29, 2024
28 checks passed
@euri10 euri10 deleted the fix-optional-list-multipart-data branch April 29, 2024 08:51
peterschutt pushed a commit that referenced this pull request May 1, 2024
…#3408)

* Fix optional sequence in multipart data validation

* Fix typing

* Handle inline annotation

* ignore pyright

---------

Co-authored-by: euri10 <benoit.barthelet@gmail.com>
(cherry picked from commit b9e501f)
peterschutt pushed a commit that referenced this pull request May 2, 2024
…#3408)

* Fix optional sequence in multipart data validation

* Fix typing

* Handle inline annotation

* ignore pyright

---------

Co-authored-by: euri10 <benoit.barthelet@gmail.com>
(cherry picked from commit b9e501f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: cant upload one file only if type is list[UploadFile] | None
5 participants