grails / grails-cache

Grails Cache Plugin
https://plugins.grails.org/plugin/grails/cache
23 stars 39 forks source link

@Cacheable annotation doesn't work with @CurrentTenant #56

Open dpcasady opened 6 years ago

dpcasady commented 6 years ago

Given a simple service class annotated with @CurrentTenant:

@CurrentTenant
@Transactional(readOnly = true)
class MultiTenantCachingService {

    @Cacheable('test')
    def serviceMethod() {

    }
}

Calling serviceMethod() throws the following exception:

No such property: tenantId for class: org.grails.MultiTenantCachingService
groovy.lang.MissingPropertyException: No such property: tenantId for class: org.grails.MultiTenantCachingService
    at org.grails.MultiTenantCachingServiceSpec.$tt__$spock_feature_0_1(MultiTenantCachingServiceSpec.groovy:29)
    at org.grails.MultiTenantCachingServiceSpec.multi-tenant service method with @Cacheable annotation doesn't throw an exception_closure2(MultiTenantCachingServiceSpec.groovy)
    at groovy.lang.Closure.call(Closure.java:418)
    at groovy.lang.Closure.call(Closure.java:434)
    at grails.gorm.transactions.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:68)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at grails.gorm.transactions.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:65)
    at org.grails.MultiTenantCachingServiceSpec.multi-tenant service method with @Cacheable annotation doesn't throw an exception(MultiTenantCachingServiceSpec.groovy)

It looks like the AST triggered by the @Cacheable annotation isn't playing nicely with the @CurrentTenant annotation.

Here's an example application using v4.0.1 of the plugin that demonstrates the issue: https://github.com/dpcasady/multi-tenant-cacheable

It has one integration test that when run will throw the exception above.

dpcasady commented 6 years ago

Nevermind this issue, it looks like it was fixed in abb34dc6293fb6abdcea91ad9e2e0f4ed0d15ee4.

Any plans to include this in a release soon?