Skip to content

Avoid matching multipart parameters annotated with @ModelAttribute #3277

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

onobc
Copy link
Contributor

@onobc onobc commented Apr 24, 2025

The ProxyHandlerMethodArgumentResolver now avoids matching multipart parameters annotated with @ModelAttribute. This allows multipart parameters to be handled by RequestParamMethodArgumentResolver which properly handles multipart arguments.

In 3.3.3 the ProxyingHandlerMethodArgumentResolver would report that it does not support the @ModelAttribute MultipartFile file parameter and then the next handler in the chain (RequestParamMethodArgumentResolver) was able to properly handle the multipart file arg.

In 3.3.4 (commit) the ProxyingHandlerMethodArgumentResolver reports that it does support the @ModelAttribute MultipartFile file parameter and then it fails to properly handle the multipart file arg.

Fixes #3258
Related tickets #2937

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

The ProxyHandlerMethodArgumentResolver now avoids matching multipart parameters annotated with @ModelAttribute. This allows multipart parameters to be handled by RequestParamMethodArgumentResolver which properly handles multipart arguments.

Fixes spring-projects#3258
Related tickets spring-projects#2937

Signed-off-by: Chris Bono <[email protected]>
@onobc onobc added the type: bug A general bug label Apr 24, 2025
@onobc onobc requested review from odrotbohm and mp911de April 24, 2025 15:53
if (parameter.getParameterAnnotation(ProjectedPayload.class) != null
|| parameter.getParameterAnnotation(ModelAttribute.class) != null) {
// Annotated parameter (excluding multipart @ModelAttribute)
if (parameter.hasParameterAnnotation(ProjectedPayload.class) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the proxy handler does not properly handle multipart arguments, but the request param method handler does properly support multipart params. Is this the proper fix or should the proxy handler also support multipart args properly? cc: @odrotbohm @mp911de

Copy link
Member

Choose a reason for hiding this comment

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

We have various aspects here. We should deprecate unannotated proxying as that has proven to cause quite some issues. We also need to have a plan how to achieve this and how our migration path would look like.

I'm thinking about:

  • (backport) 3.4.x: Introduce a warning log if a parameter is not annotated with @ProjectedPayload that this style is deprecated and that we will drop support for projections if a parameter is not annotated with @ProjectedPayload
  • 3.5: stop supporting parameters that are not annotated with @ProjectedPayload but keep the logging
  • 4.0: remove logging

Introducing warn logging can cause quite some fallout, so we should be mindful about the conditions and maybe once we have seen a parameter, that we do not repeat logging (caching?) for that particular occurence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spring Data Commons 3.3.4 breaks @ModelAttribute handling
2 participants