Skip to content

#2590 fix: enforce unique constraints during UPDATE operations #2591

Merged
robfrank merged 3 commits intomainfrom
fix/2590-unique-field-duplicate-update
Oct 1, 2025
Merged

#2590 fix: enforce unique constraints during UPDATE operations #2591
robfrank merged 3 commits intomainfrom
fix/2590-unique-field-duplicate-update

Conversation

@robfrank
Copy link
Collaborator

@robfrank robfrank commented Oct 1, 2025

This pull request addresses enforcement of unique constraints during update operations in the database engine. The main change ensures that unique index constraints are properly checked not only on add operations but also on replace operations. Additionally, comprehensive tests have been added to verify correct behavior when updating values that should or should not violate unique constraints.

Unique constraint enforcement:

  • Updated the unique index key checking logic in TransactionIndexContext.java to enforce unique constraints during both ADD and REPLACE operations, ensuring that updates do not bypass uniqueness checks.

Testing and validation:

  • Added a new test file Issue2590Test.java with multiple test cases to verify:
    • Unique constraints are enforced during updates, including updates to duplicate values and updates to null.
    • Valid updates to new unique values succeed as expected.
    • Attempts to insert or update to duplicate values correctly throw DuplicatedKeyException.

@robfrank robfrank added this to the 25.9.1 milestone Oct 1, 2025
@robfrank robfrank linked an issue Oct 1, 2025 that may be closed by this pull request
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where unique constraints were not properly enforced during database UPDATE operations. By modifying the transaction index context to include REPLACE operations in its uniqueness checks and adding comprehensive unit and integration tests, this change significantly improves data integrity, ensuring that unique keys are maintained across all data modification actions.

Highlights

  • Enhanced Unique Constraint Enforcement: The core logic for unique index key checking in TransactionIndexContext.java has been updated to correctly enforce unique constraints during both ADD and REPLACE operations, closing a loophole where UPDATE operations could bypass these checks.
  • Extensive Test Coverage: Two new test files, Issue2590Test.java and Issue2590UniqueConstraintUpdateIT.java, have been introduced. These tests cover a wide range of scenarios, including updates to null values, attempts to update to existing duplicate values (which should fail), and successful updates to new unique values, ensuring robust validation of the fix in both embedded and remote database contexts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses a critical bug by enforcing unique constraints during UPDATE operations. The change in TransactionIndexContext.java is concise and accurate. The newly added tests in Issue2590Test.java and Issue2590UniqueConstraintUpdateIT.java are comprehensive, covering a wide range of scenarios including remote and HTTP API calls. I've identified a few areas for improvement in the test files, such as removing leftover debugging code, fixing an incomplete test case, and improving consistency. Overall, this is a solid contribution that effectively resolves the issue.

@codacy-production
Copy link

codacy-production bot commented Oct 1, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.03% 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (959b2af) 72484 45719 63.07%
Head commit (1672448) 72483 (-1) 45742 (+23) 63.11% (+0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2591) 1 1 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank merged commit 5a88473 into main Oct 1, 2025
17 of 21 checks passed
@robfrank robfrank deleted the fix/2590-unique-field-duplicate-update branch October 1, 2025 09:45
@lvca lvca added the bug label Oct 9, 2025
robfrank added a commit that referenced this pull request Nov 10, 2025
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

Successfully merging this pull request may close these issues.

Store a duplicated key on a unique field.

2 participants