You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "jamesfredley (via GitHub)" <gi...@apache.org> on 2026/02/20 17:31:42 UTC
[PR] fix: copy missing fields in AbstractDetachedCriteria.clone() [grails-core]
jamesfredley opened a new pull request, #15424:
URL: https://github.com/apache/grails-core/pull/15424
## Summary
- `AbstractDetachedCriteria.clone()` was missing `connectionName`, `lazyQuery`, and `associationCriteriaMap`
- This caused `withConnection()` settings to be silently lost when chained methods like `max()`, `offset()`, or `sort()` were called afterward, because each internally clones the criteria
## Example of the bug
```groovy
def criteria = Product.where { amount > 100 }
.withConnection('secondary')
.max(10) // clones internally, loses connectionName
criteria.list() // queries DEFAULT datasource instead of 'secondary'
```
## Changes
- **`AbstractDetachedCriteria.clone()`**: Added copying of `connectionName`, `lazyQuery`, and `associationCriteriaMap` (as a shallow copy)
- **`DetachedCriteriaCloneSpec`**: 7 new unit tests verifying clone preserves all fields, creates independent map copies, and that `withConnection().max()` chaining works correctly
## Test Results
- `DetachedCriteriaCloneSpec`: 7/7 pass
- `codeStyle`: pass
Fixes #15422
Reproducer: https://github.com/jamesfredley/grails-detachedcriteria-clone-connection
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: copy missing fields in AbstractDetachedCriteria.clone() [grails-core]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley merged PR #15424:
URL: https://github.com/apache/grails-core/pull/15424
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org