borinquenkid commented on code in PR #16820:
URL: https://github.com/apache/grails-core/pull/16820#discussion_r4449305824
##########
grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy:
##########
@@ -739,7 +742,7 @@ class DetachedCriteria<T> extends
AbstractDetachedCriteria<T> implements GormOpe
GormStaticApi staticApi =
GormRegistry.instance.findStaticApi(targetClass, connectionName)
staticApi.withDatastoreSession { Session session ->
- applyLazyCriteria()
+ DetachedCriteria<T> effective = materializeLazyCriteria()
Query query
if (alias && (session instanceof QueryAliasAwareSession)) {
query = session.createQuery(targetClass, alias)
Review Comment:
Fixed in 11782b1be2: query creation reads the materialized alias.
##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy:
##########
@@ -1118,6 +1124,22 @@ abstract class AbstractDetachedCriteria<T> implements
Criteria, Cloneable {
this.with(criteria)
}
+ /**
+ * Returns this criteria with its deferred query applied, without mutating
it: the original keeps the
+ * deferred query, so a criteria shared between threads materializes a
copy each time and no deferred
+ * definition is applied twice.
+ */
+ AbstractDetachedCriteria<T> materializeLazyCriteria() {
+ Closure pending = lazyQuery
+ if (pending == null) {
+ return this
+ }
+ AbstractDetachedCriteria<T> materialized = clone()
Review Comment:
Fixed in e9e562667f: `clone()` now copies the association nodes so a
deferred `createAlias()` no longer touches the original.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]