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

Wrong data generated on 2nd call to build() with email & presense of unique constraints #91

Open
erichelgeson opened this issue Jan 8, 2018 · 3 comments

Comments

@erichelgeson
Copy link

erichelgeson commented Jan 8, 2018

Given an email constraint, the first .build() generates the correct email. But the second time .build() is called it generates the value x which is not a valid email. I know there are limitations with unique but it is odd it generates the right data the first time & not the second. Note that even unique: false causes this.

See example spec here https://github.com/erichelgeson/btdIssue/blob/master/src/test/groovy/test/FooControllerSpec.groovy

This did work in b-t-d 3.0.1 & Grails 3.2.11

Environment: Grails 3.3.2, b-t-d 3.3.0.RC1, Mac OSX 10.13.2, JDK 8u152

@longwa
Copy link
Owner

longwa commented Jan 8, 2018

It works for me when I remove the unique constraint. It should stop populating data once the EmailConstraintHandler builds the email, but when it's unique that email address fails validation so it continues through the handler chain and eventually the blank handler puts the X in (as you see in the logs).

I'm not sure why it worked before for the unique: true case. For unique constraints, we usually just add something to TestDataConfig to generate a sequence of values.

I do have plans to add proper unique support as part of a second round of refactoring.

@longwa
Copy link
Owner

longwa commented Jan 8, 2018

Oh, I see. If you say unique: false, it still fails but if you remove unique constraint completely it works.

@longwa
Copy link
Owner

longwa commented Jan 8, 2018

Ok, this seems like a GORM issue. Specifying unique: false has the same behavior as unique: true. I think they are just checking for the existence of the constraint and not the actual value. I created a test in BTD:

    void testBuildEmailAddressTwiceManually() {
        when:
        def obj = new Standalone(name: 'Foo', age: 10, emailAddress: 'a@b.com', created: new Date()).save(flush: true, failOnError: true)

        then:
        obj.emailAddress == "a@b.com"

        when:
        obj = new Standalone(name: 'Foo', age: 10, emailAddress: 'a@b.com', created: new Date()).save(flush: true, failOnError: true)

        then:
        obj
        obj.emailAddress == "a@b.com"
    }

This just builds the thing manually and it fails, even with unique: false. If I remove it completely, it works fine.

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

2 participants