-
Notifications
You must be signed in to change notification settings - Fork 44
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
fix: Handle multiple nil values on unique indexed fields #2178
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #2178 +/- ##
===========================================
+ Coverage 74.13% 74.16% +0.02%
===========================================
Files 256 256
Lines 25368 25372 +4
===========================================
+ Hits 18806 18815 +9
+ Misses 5279 5276 -3
+ Partials 1283 1281 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does feel like the wrong approach. I think users should still be allowed nil values in indexed fields, especially considering that the GQL types are nillable (Int
vs Int!
).
The SQL standards for this allow multiple nil values in a column with a unique constraint. Microsoft SQL Server naturally ignores this, and only permits a single nil value.
https://stackoverflow.com/questions/767657/how-do-i-create-a-unique-constraint-that-also-allows-nulls (check top answer).
added a task for multiple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and I'm glad not much production code was required. I do think more tests are required though.
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestUniqueIndexCreate_UponAddingDocWithExistingNilValue_ReturnError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Can you please add a test that shows a single document with a nil indexed value succeeding? This way if this (multiple nil values) test is deleted (e.g. when switching to allowing multiple nils) we do not lose coverage of the single nil happy-case.
todo: Can you please add a test with a filter eq nil?
todo: Can you please add some tests for composite indexes with all-nil and mixed nil/non-nil values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test for a single nil
value was always there
defradb/db/indexed_docs_test.go
Line 1031 in d2cfd87
func TestUnique_IfIndexedFieldIsNil_StoreItAsNil(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add it as an integration test please? It will make it much easier to discover, and it will be able to take advantage of all our integration test related perks (such as mutation and client types, change detection, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current test already includes a successful addition of a document with a nil
value:
testUtils.CreateDoc{
CollectionID: 0,
Doc: `
{
"name": "Keenan"
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `
{
"name": "Andy"
}`,
ExpectedError: db.NewErrCanNotIndexNonUniqueField("bae-2159860f-3cd1-59de-9440-71331e77cbb8", "age", nil).Error(),
},
Adding another one would be redundant.
I will add a test with filtering on nil
value.
todo: Can you please add some tests for composite indexes with all-nil and mixed nil/non-nil values?
composite indexes is WIP on another branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current test already includes a successful addition of a document with a nil value:
Yes I saw that, but an independent successful test would be useful. If this (multiple nil values) test is deleted (e.g. when switching to allowing multiple nils) we do not lose coverage of the single nil happy-case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an explicit test
91fa97d
to
a21a95c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
…rk#2178) ## Relevant issue(s) Resolves sourcenetwork#2174 sourcenetwork#2175 ## Description This change fixes how nil values are handled on unique indexes
…rk#2178) ## Relevant issue(s) Resolves sourcenetwork#2174 sourcenetwork#2175 ## Description This change fixes how nil values are handled on unique indexes
Relevant issue(s)
Resolves #2174 #2175
Description
Forbid
nil
values for fields that are unique-indexed.Tasks
How has this been tested?
Integration and unit tests
Specify the platform(s) on which this was tested: