grails 3.1.9 can not set request attribute named "session" in interceptor or action
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Steps to Reproduce
1. Create a app with a domaon Foo and FooController/FooInterceptor
2. In controller and interceptor, put following test code
Controller:
```
def test(){
request['foobar'] = 'foobar' // success!
request.setAttribute('session','foobar_session'); // failed!
request['session'] = 'foobar_session' // failed!
render "OK"
}
```
Interceptor:
```
boolean before() {
request.setAttribute('session','foobar_session'); // success!
request['session'] = 'foo'; // failed!
return true
}
```
1. Run app and access from browser, the error message occurred:
```
ERROR org.grails.web.errors.GrailsExceptionResolver - GroovyRuntimeException occurred when processing request: [GET] /user/test
Cannot set read-only property: session. Stacktrace follows:
groovy.lang.GroovyRuntimeException: Cannot set read-only property: session
at hellog3.UserInterceptor.before(UserInterceptor.groovy:8)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
```
```
### Expected Behaviour
- Behavior of reqeust.setAttribute('foo') and request['foo'] should be the same
- attribute 'session' in request object ( the request['session']) should not be occupied by the framework
### Actual Behaviour
- Got exception: "Cannot set read-only property: session"
### Environment Information
- **Operating System**: OSX 10.10
- **Grails Version:** 3.1.9
- **JDK Version:** 1.8
- **Container Version (If Applicable):** N/A
### Example Application
- N/A
```
Contributor guide
Research direction
Reproduce the behavior in FooController and FooInterceptor using the request.setAttribute and request[...] examples. Start by tracing how Grails 3.1.9 exposes the request session property, then verify that both forms can set an attribute named session without the read-only property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100