Skip to content

@SessionAttributes not populated when going directly to POST and redirecting while ignoreDefaultModelOnRedirect=true [SPR-12542] #17146

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-12542 and commented

I have a controller annotated with @SessionAttributes("cart") and q request handling method like this:

@RequestMapping(value = "/cart", method = RequestMethod.POST)
public String addToCart(@RequestParam("product") Long productId,  @ModelAttribute Cart cart) {

   …
   return "redirect:…";
}

If the call to that controller method is the very first one made to that controller in the session, the Cart object is created by an @ModelAttribute annotated method and handed to the method execution. The cart is then not added to the session attributes if ignoreDefaultModelOnRedirect=true as ModelFactory.updateModel(…) looks up the Model from the ModelAndViewContainer which returns the redirect model for a redirect view.

Once you issue a request to a controller method not returning a redirect view, the cart is added to the session and looked up from it for the invocation of the method above. Thus subsequent modifications of the object transparently end up in the session.

We should make sure the default model is used to populate the session attributes independently from the view type that is returned.


Affects: 4.0.8, 4.1.3

Issue Links:

Referenced from: commits ea05e0b

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions