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

[release/9.0] Avoid infinite recursion on identifying shadow FKs #34892

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

AndriySvyryd
Copy link
Member

@AndriySvyryd AndriySvyryd commented Oct 11, 2024

Fixes #34875

Description
When a user configures a foreign key property without specifying the type or whether it's required EF creates a shadow nullable property by default.

  1. If the entity type in question is owned or is the join entity type in a many-to-many relationship, EF will configure the FK properties as the primary key (i.e. an identifying FK).
  2. This will mark the properties as required and trigger a convention to change their types to be non-nullable.
  3. This triggers a convention to check again whether the new property types correspond to their nullability, but the condition relies only on the requiredness of the FKs defined on the properties, so it decided that that should be nullable instead.
  4. After the properties are made nullable again the key is reapplied on them, leading to step 2

EF throws a custom exception instead of a StackOverflow because the convention implementation unwraps the recursive calls.

Customer impact
For affected models, an exception is thrown whenever the context is used. There are several workarounds for the reported scenario, but identifying shadow FKs are pretty common, so this can potentially affect a significant portion of users.

How found
Customer reported on 8.0.10

Regression
Yes, from 8.0.8. This issue is old, but it was made easier to hit by #34388

Testing
Test added.

Risk
Low.

@SamMonoRT
Copy link
Member

approved via email

@AndriySvyryd AndriySvyryd merged commit a0b9d88 into release/9.0 Oct 14, 2024
7 checks passed
@AndriySvyryd AndriySvyryd deleted the Issue34875_9.0 branch October 14, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants