DM-46002: Locations for validation errors on constraints reported incorrectly #102
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.
This fixes an issue where the Pydantic error locations for constraint objects were reported incorrectly, due to how the model objects were constructed.
Instead of using a custom
create_constraints()
function, a Pydantic discriminated union was used to automatically construct the objects based on thetype
field. This seems to fix the issue where error locations were reported incorrectly.Sample new error location is:
tables.0.constraints.0.Unique.@id
.This is not exactly the same scheme that shows for some other types of objects, but it is at least clear now that the error has occurred in a specific constraint denoted by the index.
As a result of the above changes, usage of the
type
field in themetadata
andtap
modules was removed in favor of checking the constraint's type usingisinstance()
. This is required based on removal of thetype
field from theConstraint
class. (Since it should never be instantiated, thetype
field is not needed on this class and including it creates typing conflicts with its child classes. Each constraint class now defines this separately and not as a common field from the parent class.)A few additional changes were included which do not have associated tickets:
Constraint
test case intest_datamodel
(See 1706788).deferrable
field onConstraint
must be set toTrue
ifinitially
is not None. This requirement was indicated in comments but never implemented.Literal
toConstraint
in the data model that limits the value ofinitially
toIMMEDIATE
orDEFERRED
as these are the only valid values for anINITIALLY
clause in DDL.annotations
field on theConstraint
class. (This field was erroneously carried over from the old "simple model" but has never been used within a production schema, to my knowledge.)Index
test case intest_datamodel
(See 6631610).Checklist
docs/changes