Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] #[MapUploadedFile] throws http exception on empty files array if argument not nullable nor has default value#61381

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:7.3fromhwawshy:fix_61376
Aug 19, 2025

Conversation

@hwawshy
Copy link
Contributor

QA
Branch?7.3
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#61376
LicenseMIT

Fixes#61376

santysisi reacted with thumbs up emojisantysisi reacted with heart emojisantysisi reacted with rocket emoji
Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

I understand that this is a bug fix, but also a behavior change, so I'm not sure we should do it in 7.3.
@symfony/mergers Thoughts?

@symfonysymfony deleted a comment fromcarsonbotAug 19, 2025
@Spomky
Copy link
Contributor

Indeed. Previously it returned an empty array ornull (if the argument was nullable). Now it always returnsnull and may cause errors for non-nullable array arguments. An argument like#[MapUploadedFile] array $files should return[] and notnull.

}

return$files;
return$request->files->get($attribute->name ??$argument->getName());
Copy link
Member

@nicolas-grekasnicolas-grekasAug 19, 2025
edited
Loading

Choose a reason for hiding this comment

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

What looks strange to me in the previous code is defaulting to an array without caring about the accepted type. To reduce the behavioral diff, we should continue to default to an array when arrays are accepted - and when not, then we should fix the behavior.

This would need a new test case for the array-case.

Suggested change
return$request->files->get($attribute->name ??$argument->getName());
if (!($files =$request->files->get($attribute->name ??$argument->getName())) && ($argument->isNullable() ||$argument->hasDefaultValue())) {
returnnull;
}
return$files ?? ('array' ===$argument->getType() ? [] :null);

Spomky reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

I see at least 4 test cases that should be verified when no file is provided:

  • #[MapUploadedFile] array $files => should return an empty array
  • #[MapUploadedFile] ?array $files => should returnnull
  • #[MapUploadedFile] UploadedFile $file => should returnnull and an exception will be thrown
  • #[MapUploadedFile] UploadedFile ?$file => should returnnull

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I understand returning an empty array for the sake of BC, but IMO an absence of value should be denoted bynull and not an empty array. The user indicates the value is optional by making the argument nullable (that's also what the docs currently say), otherwise anHttpException should be thrown.

Choose a reason for hiding this comment

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

That's not how this works for arrays for the other value resolvers. We have to be consistent.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Alright, I applied your suggestion and added the missing test cases. I am not sure if the failed pipelines are related to my changes.

nicolas-grekas and Spomky reacted with heart emoji
…array if argument not nullable nor has default value
@nicolas-grekas
Copy link
Member

Thank you@hwawshy.

Spomky reacted with thumbs up emojihwawshy reacted with heart emoji

@nicolas-grekasnicolas-grekas merged commit4102229 intosymfony:7.3Aug 19, 2025
5 of 11 checks passed
@hwawshyhwawshy deleted the fix_61376 branchAugust 19, 2025 12:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@SpomkySpomkySpomky left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@Jean-BeruJean-BeruJean-Beru approved these changes

@santysisisantysisisantysisi approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.3

Development

Successfully merging this pull request may close these issues.

7 participants

@hwawshy@Spomky@nicolas-grekas@fabpot@Jean-Beru@santysisi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp