GORM: Inconsistent DetachedCriteria composition when using real object instead of closure
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
I observed inconsistent behavior and API when trying to reuse and compose DetachedCriteria instances together:
- Criteria composition seems to only work with closure based detached criterias
- It seems there is no way to compose two detached criteria instances together (`DetachedCriteria.where(DetachedCriteria)`)
- closure based detached criterias do not work in a type-safe environment @GrailsCompileStatic
Tested with **Grails 3.2.4**
Some examples to demonstrate
```
// this is the only variant that works
def myFilter = {} as DetachedCriteria
Person.where(myFilter)
```
```
// this doesn't work, resulting in exception:
// No signature of method: Person.where() is applicable for argument types: (grails.gorm.DetachedCriteria)
def myFilter = new DetachedCriteria(Person).build {}
Person.where(myFilter)
```
```
// type-safe variant mit @GrailsCompileStatic doesn't even compile:
// [Static type checking] - Cannot assign value of type groovy.lang.Closure to variable of type grails.gorm.DetachedCriteria
DetachedCriteria myFilter = {} as DetachedCriteria
Person.where(myFilter)
```
```
// DetachedCriteria closure coercion inconsistency:
def myCriteria = {} as DetachedCriteria
log.debug "${myCriteria instanceof DetachedCriteria}" // -> false
def myPredicate = {} as Predicate
log.debug "${myPredicate instanceof Predicate}" // -> true
```
Contributor guide
Research direction
Reproduce the DetachedCriteria and Person.where examples from the issue on Grails 3.2.4, then inspect the DetachedCriteria API and where entry point. Compare closure-based, constructed, and @GrailsCompileStatic cases; done means their composition and type behavior are consistent or the supported limitations are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100