Skip to content

Gh 14503 unique discriminator null spec#15653

Open
jagiro wants to merge 1 commit into
apache:8.0.x-hibernate7from
jagiro:gh-14503-unique-discriminator-null-spec
Open

Gh 14503 unique discriminator null spec#15653
jagiro wants to merge 1 commit into
apache:8.0.x-hibernate7from
jagiro:gh-14503-unique-discriminator-null-spec

Conversation

@jagiro
Copy link
Copy Markdown

@jagiro jagiro commented May 11, 2026

Follow-up to #14503 per @borinquenkid's request:
"add a spec to H5 and H7 core modules and mark them as pending and then we
will follow up on the fix"
.

This PR adds the failing scenario as a @PendingFeature Spock test in both
grails-data-hibernate5/core and grails-data-hibernate7/core test modules.
It does not propose a fix. The fix approach is still open per
@jdaugherty's "we should discuss this as a team before proposing a fix"
(option 1 — skip-on-null SQL-standard, option 2 — explicit IS NULL check,
or configurable).

What this PR adds

In both modules, MultiColumnUniqueConstraintSpec.groovy gains:

  • A new @Entity DomainTwo with name unique: ['discriminator'] and
    discriminator nullable: true.
  • A new @PendingFeature test case:
    "save with null discriminator succeeds when only non-null discriminator
    rows exist for the same main field"
    .
  • The new domain registered in manager.addAllDomainClasses(...).

Verification done locally

  • ./gradlew :grails-data-hibernate5-core:test --tests "*MultiColumnUniqueConstraintSpec*"
    → 4 tests, 3 passed, 1 skipped (the new @PendingFeature, as expected).
  • ./gradlew :grails-data-hibernate7-core:test --tests "*MultiColumnUniqueConstraintSpec*"
    → same result.
  • Sanity check: temporarily removed @PendingFeature from the H5 file and
    re-ran. The test FAILED with Condition not satisfied: saved != null
    (the save() call returns null because the validator rejects the new row
    as a duplicate even though the existing row has a non-null discriminator).
    Restored @PendingFeature after confirming.
  • Full module test runs (./gradlew :grails-data-hibernate5-core:test :grails-data-hibernate7-core:test): 2892 tests, 5 failed, 30 skipped.
    All 5 failures are pre-existing environmental issues (testcontainers
    cannot find a Docker environment on this machine):
    RLikeHibernate7Spec (3 tests), GrailsSequenceGeneratorEnumSpec,
    HibernateDatastoreIntegrationSpec. None of the failures touch the
    files modified in this PR. CI with Docker available should report
    these as passing.

When the fix lands and the test starts passing, Spock will throw
PendingFeatureNotFinished as a reminder to remove the annotation.

Note on AI tooling

This contribution was prepared with assistance from Claude (Anthropic).
The reproducer was first verified in an external Grails 7.x application
and the spec was authored, run, and sanity-checked locally before
submission, per the ASF Generative Tooling policy.

…e#14503)

Adds a Spock @PendingFeature regression test to MultiColumnUniqueConstraintSpec
in both grails-data-hibernate5 and grails-data-hibernate7 core test modules.

The test exercises the bug described in apache#14503: when a domain declares
`unique: [discriminator]` and the discriminator is nullable, saving a new
row with the discriminator set to null currently fails validation if any
row with the same main field value already exists, regardless of the
existing row's discriminator value. The validator emits SQL without the
discriminator clause.

The test is marked @PendingFeature with a reason referencing the issue,
so it does not fail the build. When the fix lands and the test starts
passing, Spock will fail with PendingFeatureNotFinished as a reminder to
remove the annotation.

No fix is proposed here per the maintainers' request to discuss the fix
approach as a team. This change only codifies the failing scenario as a
reproducer in the framework's own test suite.
@jdaugherty
Copy link
Copy Markdown
Contributor

@jagiro I'm guessing you tried to merge 8.x into 7.x? Should the base of this be 8.x?

@jdaugherty jdaugherty changed the base branch from 7.0.x to 8.0.x-hibernate7 May 11, 2026 19:18
@jdaugherty
Copy link
Copy Markdown
Contributor

@jagiro I see in your issue comment this was meant to be merged against 8.0.x-hibernate7 so I've updated the base branch.

@jdaugherty jdaugherty requested a review from borinquenkid May 11, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants