Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity.find with closure breaks in Spock then: block #360

Open
sbglasius opened this issue Aug 30, 2021 · 0 comments
Open

Entity.find with closure breaks in Spock then: block #360

sbglasius opened this issue Aug 30, 2021 · 0 comments

Comments

@sbglasius
Copy link

When doing a query with a .find { } method on a domain object (in this case in a Grails 4.0.11 application) the generated detached criteria does not contain the criteria defined in code.

Example:

    def "test where query is in then block with def"() {
        given:
        Bundle bundle = new Bundle(name: 'bundle')
        bundle.addToVersions(name: '1.0')
        bundle.save(flush: true)

        when:
        bundle.addToVersions(name: '1.1')
        bundle.save(flush: true)

        then:
        def result = BundleVersion.find({ name == '1.1' && bundle.name == 'bundle' })
        result.name == '1.1'
    }

where the result is a variable, then it works. But if the variable is omitted like this:

    def "test where query is in then block without def"() {
        given:
        Bundle bundle = new Bundle(name: 'bundle')
        bundle.addToVersions(name: '1.0')
        bundle.save(flush: true)

        when:
        bundle.addToVersions(name: '1.1')
        bundle.save(flush: true)

        then: "this will fail - which is not expected"
        BundleVersion.find({ name == '1.1' && bundle.name == 'bundle' }).name == '1.1'
    }

Then 1.0 is found which is unexpected.

An example of this behaviour can be found here: https://github.com/sbglasius/gorm-query-bug

Discovered by @Thomas58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant