Skip to content
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

Add model validation for nested dependents #23229

Closed
AndriySvyryd opened this issue Nov 7, 2020 · 9 comments · Fixed by #24573
Closed

Add model validation for nested dependents #23229

AndriySvyryd opened this issue Nov 7, 2020 · 9 comments · Fixed by #24573
Assignees
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Nov 7, 2020

If there are no non-PK required properties.

See GraphUpdatesSqlServerTest.Owned.Required_one_to_one_are_cascade_deleted

Model:

Root.RequiredSingle is an optional dependent

  1. Add r.Navigation(e => e.Single).IsRequired(); to mark Root.RequiredSingle.Single as required

  2. Remove RequiredSingle1.Bool

@AndriySvyryd
Copy link
Member Author

Related: #21488

@smitpatel
Copy link
Contributor

I updated model according to above. Test still fails in assert after loading required graph.

When we load root, root->RequiredSingle materializes always because there is no differentiating property. root->RequiredSingle->Single is not materialized because the values are null in the bool column inside RequiredSingle2 class. Test seems like making wrong assertion. @AndriySvyryd ?

@smitpatel
Copy link
Contributor

smitpatel commented Dec 9, 2020

Investigating more - The model falls into a kind of invalid model.
RequiredSingle is optional but nested Single is required.
Due to lack of properties in RequiredSingle it acts as required hence we materialize the instance but we cannot materialize Single since it was deleted along with RequiredSingle (due to it being required).

We need to warn for this and also make the model also act like RequiredSingle is actually required.

@smitpatel smitpatel removed this from the 6.0.0 milestone Dec 9, 2020
@smitpatel smitpatel removed their assignment Dec 9, 2020
@ajcvickers
Copy link
Contributor

Based on current design, we should add model validation to detect when there is an optional dependent that doesn't have any required properties that are not shared.

@ajcvickers ajcvickers modified the milestones: 5.0.x, 6.0.0 Dec 15, 2020
@ajcvickers ajcvickers changed the title Check nested required dependent to determine whether dependent exists Add model validation for nested dependents Dec 15, 2020
@smitpatel
Copy link
Contributor

Design meeting N notes:

  • We will add a IModelFinalizingConvention which would log and convert the dependent to required dependent so that metadata can be read that way at runtime.
  • We will also remove the code from SQL which tries to add rows for nested dependents.

@smitpatel
Copy link
Contributor

Design meeting N+ M notes:

  • We will add validation in model.
  • If optional dependent doesn't have a required identifying property,
    • If there are no nested dependents then warn
    • If there are nested dependents then throw.

@smitpatel
Copy link
Contributor

Older snapshots which are already having this kind of faulty model would start throwing exception (tests are failing in source rn).

What direction are we taking on it? @dotnet/efteam

@AndriySvyryd
Copy link
Member Author

We don't run model validation on snapshots

@smitpatel
Copy link
Contributor

Looks like test in model snapshot processor is failing because the runtime model is faulty. I will debug more.

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 3, 2021
smitpatel added a commit that referenced this issue Apr 3, 2021
smitpatel added a commit that referenced this issue Apr 5, 2021
@ghost ghost closed this as completed in #24573 Apr 6, 2021
ghost pushed a commit that referenced this issue Apr 6, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview4 Apr 26, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview4, 6.0.0 Nov 8, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants