Grails

Filters are executed multiple times

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Not A Bug
  • Affects Version/s: 1.2 final
  • Fix Version/s: 1.2.1
  • Component/s: None
  • Labels:
    None
  • Environment:
    XPSP2,JDK 1.6_17

Description

If you define a filter like this:

class StorefrontFilters {
	def filters = {
		handleSomething(controller: '*', action: '*') {
			before = {
				log.info "handleSomething executed"
			}
		}

		handleSomething2(controller: '*', action: '*') {
			before = {
				log.info "handleSomething2 executed"
			}
		}
	}
}

The each before-closure is executed 2 times on each request. If I define another filter
each before interceptor will be executed 3 times and so on.
This was working in grails 1.1.1

Output would be

handleSomething executed
handleSomething2 executed
handleSomething executed
handleSomething2 executed

Activity

Hide
Jeff Brown added a comment -

There may be something in your application that is triggering the behavior (possibly a redirect?). I have attached a Grails 1.2 project which uses filters defined just like yours and this app appears to behave as designed, the filters are only executed once per request.

If you can attach a project that demonstrates the behavior you are seeing, that would be helpful.

Show
Jeff Brown added a comment - There may be something in your application that is triggering the behavior (possibly a redirect?). I have attached a Grails 1.2 project which uses filters defined just like yours and this app appears to behave as designed, the filters are only executed once per request. If you can attach a project that demonstrates the behavior you are seeing, that would be helpful.
Hide
Jeff Brown added a comment -

Malte,

Can you attach a demonstrative sample application or describe some details that might help us reproduce the problem?

Show
Jeff Brown added a comment - Malte, Can you attach a demonstrative sample application or describe some details that might help us reproduce the problem?
Hide
Malte Huebner added a comment -

Hi Jeff,

thank you for your demo app. Until now I can not reproduce this with your app. But the bug is still existing
in my grails application. I have to figure out why this is happening. My current app is really complex and I cannot attach it.
Currently I am trying to reproduce the behaviour in "filtertest". I will post a comment when I finished testing.

Show
Malte Huebner added a comment - Hi Jeff, thank you for your demo app. Until now I can not reproduce this with your app. But the bug is still existing in my grails application. I have to figure out why this is happening. My current app is really complex and I cannot attach it. Currently I am trying to reproduce the behaviour in "filtertest". I will post a comment when I finished testing.
Hide
Malte Huebner added a comment -

Ok, I finally found the source for this issue. The title of this bugrepot must be "Filters are not executed one time for each request but for every g:include of a controller action".
I had 2 g:include expressions in my view - each of them render output from a controller action. So the filter was executed for the controller itself and for each of the g:includes.
Is this a wanted behaviour? In grails 1.1 and up (until 1.2) the filters where not executed for each g:include.

Show
Malte Huebner added a comment - Ok, I finally found the source for this issue. The title of this bugrepot must be "Filters are not executed one time for each request but for every g:include of a controller action". I had 2 g:include expressions in my view - each of them render output from a controller action. So the filter was executed for the controller itself and for each of the g:includes. Is this a wanted behaviour? In grails 1.1 and up (until 1.2) the filters where not executed for each g:include.
Hide
Malte Huebner added a comment -

I just noticed that this is also a problem in 1.1.1. (if it is a problem at all).

Show
Malte Huebner added a comment - I just noticed that this is also a problem in 1.1.1. (if it is a problem at all).
Hide
Jeff Brown added a comment -

I think filters should be applicable when controller actions are invoked via the include tag. For some scenarios, that may be important.

You may need to configure your filter selection criteria to not select actions that you intend to invoke with the include tag if you don't want your filters applied there.

Thanks for the input.

Show
Jeff Brown added a comment - I think filters should be applicable when controller actions are invoked via the include tag. For some scenarios, that may be important. You may need to configure your filter selection criteria to not select actions that you intend to invoke with the include tag if you don't want your filters applied there. Thanks for the input.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: