Properties of type java.time.Year are not recognized in tests
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
Using dynamic finders for properties of java.time.Year type in test code results in `InvalidDataAccessResourceUsageException` - `Cannot query (...) on non-existent property: (...)`, while in regular code it works fine.
Debugging had shown that java.time.Year is not recognized as a simple type in [MappingFactory](https://github.com/grails/grails-data-mapping/blob/master/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/MappingFactory.java).
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Create domain class with property of type java.time.Year (e.g. `year`)
2. In unit test use dynamic finder with the java.time.Year property (`findByYear()`)
### Expected Behaviour
Dynamic finder should work as in non-test code.
### Actual Behaviour
Using dynamic finder throws exception:
```Cannot query [sandbox.TestDomain] on non-existent property: year
org.springframework.dao.InvalidDataAccessResourceUsageException: Cannot query [sandbox.TestDomain] on non-existent property: year
at org.grails.datastore.mapping.simple.query.SimpleMapQuery.getValidProperty(SimpleMapQuery.groovy:751)
at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeSubQueryInternal(SimpleMapQuery.groovy:690)
at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeSubQuery(SimpleMapQuery.groovy:676)
at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeQuery(SimpleMapQuery.groovy:63)
at org.grails.datastore.mapping.query.Query.doList(Query.java:575)
at org.grails.datastore.mapping.query.Query.singleResult(Query.java:563)
at org.grails.datastore.gorm.finders.AbstractFindByFinder.invokeQuery(AbstractFindByFinder.java:35)
at org.grails.datastore.gorm.finders.AbstractFindByFinder$1.doInSession(AbstractFindByFinder.java:29)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:319)
at org.grails.datastore.gorm.finders.AbstractFinder.execute(AbstractFinder.java:42)
at org.grails.datastore.gorm.finders.AbstractFindByFinder.doInvokeInternal(AbstractFindByFinder.java:27)
at org.grails.datastore.gorm.finders.DynamicFinder.invoke(DynamicFinder.java:174)
at org.grails.datastore.gorm.finders.DynamicFinder.invoke(DynamicFinder.java:374)
at org.grails.datastore.gorm.GormStaticApi.methodMissing(GormStaticApi.groovy:173)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.staticMethodMissing(GormEntity.groovy:749)
at sandbox.TestDomainSpec.Dynamic finder should work with java.time.Year(TestDomainSpec.groovy:16)
```
### Environment Information
- **Operating System**: Windows 10
- **GORM Version:** 6.0.9.RELEASE
- **Grails Version (if using Grails):** 3.2.8
- **JDK Version:** 1.8.0_131
### Example Application
GitHub repository: https://github.com/piotrgajow/Sandbox
Branch: `grails-JavaTimeYearPropertyIssue` - https://github.com/piotrgajow/Sandbox/tree/grails-JavaTimeYearPropertyIssue
Notable files:
[Domain class](https://github.com/piotrgajow/Sandbox/blob/grails-JavaTimeYearPropertyIssue/grails-3.2.8/sandbox/grails-app/domain/sandbox/TestDomain.groovy).
Finder working properly in [Bootstrap](https://github.com/piotrgajow/Sandbox/blob/grails-JavaTimeYearPropertyIssue/grails-3.2.8/sandbox/grails-app/init/sandbox/BootStrap.groovy).
Finder not working in [test code](https://github.com/piotrgajow/Sandbox/blob/grails-JavaTimeYearPropertyIssue/grails-3.2.8/sandbox/src/test/groovy/sandbox/TestDomainSpec.groovy).
Contributor guide
Research direction
Start with MappingFactory.java and reproduce the failure using the example application's TestDomain.groovy and TestDomainSpec.groovy. Compare the working finder in BootStrap.groovy with the failing test, then verify that findByYear() works for a java.time.Year property in test code without the non-existent-property exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100