Repository navigation
Unique fields: enforce @EntityField.unique() on references and camelCase fields in memory repositories (v1.35.2) - #211
Merged
Conversation
…fields (v1.35.2) The single-field unique check compared the entity's EntityReference object with the stored referenced ID, so it never conflicted. It now shares the composite unique check's comparison (stored form, field or column, null never conflicts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- DBSQLMemoryAdapter: single-field and composite unique constraints checked in one pass, values normalized once (with the entityName); same-type values compared only by ==, not toString(). - SetEntityRepository: a unique EntityReference compares the referenced ID; a null reference never conflicts. - Tests: camelCase String/enum unique fields, an unsaved reference, both repositories. CHANGELOG: the camelCase enforcement change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #211 +/- ##
==========================================
+ Coverage 95.91% 95.96% +0.04%
==========================================
Files 75 75
Lines 25947 25943 -4
==========================================
+ Hits 24888 24895 +7
+ Misses 1059 1048 -11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DBSQLMemoryAdapternever enforced a single-field unique constraint (@EntityField.unique()) on anEntityReference<X>field: two rows referencing the same id were accepted. Postgres enforces the generatedUNIQUEconstraint (e.g.deliverer_withdrawal__pending_wallet__unique), so in-memory tests diverged from production.checkEntityFieldshad two problems:getField(theEntityReferenceobject) with==against the stored value (the referenced id).external_code) were never enforced either.Fix
DBSQLMemoryAdapter: single-field and composite (@EntityIndex(unique: true)) constraints are now checked in one pass. The entity's values are normalized once, in stored form (a reference becomes its id), andnullnever conflicts. Each entry is read by field or column name. Values of the same type are compared only by==, no longer also bytoString().SetEntityRepository: a uniqueEntityReferencefield compares the referenced id. Before, two null references counted as a duplicate, and a reference set by entity could differ from one set by id.Heads-up (in the CHANGELOG): in-memory tests that store duplicates of a camelCase unique field now fail, as they would on a SQL database.
Tests
test/bones_api_entity_index_test.dartruns on bothDBSQLMemoryAdapterandSetEntityRepository:Stringandenumunique fields: duplicates are rejected;nulls are accepted.The tests fail without the fix. The memory, repository, index and version suites pass, and
dart pub publish --dry-runreports 0 warnings.Version bumped to 1.35.2 (
pubspec.yaml,BonesAPI.VERSION, CHANGELOG).🤖 Generated with Claude Code