ruthst00 commented on issue #12081:
URL: https://github.com/apache/grails-core/issues/12081#issuecomment-5854838822
### This bug appears to exist on every major release branch from 3.0.x
through 9.0.x
The unfixed `getModel()` (only reading `MODEL_AND_VIEW`, never falling back
to `TEMPLATE_MODEL`) and the `render template: ..., model: ...` path (storing
model only in `TEMPLATE_MODEL`) are present identically across **all** branches
where the Interceptor feature exists:
| Branch | Bug present? | `Interceptor.groovy` location |
|--------|-------------|-------------------------------|
| `3.0.x` – `6.2.x` | ✅ Yes | `grails-plugin-interceptors/` |
| `7.0.x` – `9.0.x` | ✅ Yes | `grails-interceptors/` |
The `ResponseRenderer.groovy` location also varies:
- `3.0.x` – `6.2.x`: `grails-plugin-controllers/`
- `7.0.x` – `9.0.x`: `grails-controllers/`
#### Recommended fix strategy
Since this is a long-standing bug present since Grails 3.0, the fix should
be applied in order from newest to oldest **actively maintained** branches:
1. **`9.0.x`** — newest development branch (fix here first)
2. **`8.1.x`** — next active branch
3. **`8.0.x`** — current stable/active branch
4. **`7.2.x`**, **`7.1.x`** — if still maintained, backport
5. Older branches (6.x, 5.x, 4.x, 3.x) — likely EOL; backport only if
officially supported
The fix itself is the same one-liner change to `getModel()` in
`Interceptor.groovy` on each branch — add a fallback to `TEMPLATE_MODEL` when
`MODEL_AND_VIEW` is null. For example:
``` java
@Generated
Map<String, Object> getModel() {
def modelAndView = (ModelAndView)
currentRequestAttributes().getAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW,
0)
if (modelAndView != null) {
return modelAndView.modelMap
}
// Fallback: when render template: ..., model: ... is used, the model is
stored in TEMPLATE_MODEL
return (Map<String, Object>)
currentRequestAttributes().getAttribute(GrailsApplicationAttributes.TEMPLATE_MODEL,
0)
}
```
I'm happy to start working on this issue if folks agree with the assessment
above :o)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]