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

Nullable annotations for metadata 2 #23147

Merged
1 commit merged into from
Oct 31, 2020
Merged

Nullable annotations for metadata 2 #23147

1 commit merged into from
Oct 31, 2020

Conversation

roji
Copy link
Member

@roji roji commented Oct 30, 2020

Am just going to drop this here, sorry @AndriySvyryd... This annotates Model, Property, Navigation, Key, Index, and all their extensions.

  • ISkipNavigation.ForeignKey and Inverse are non-nullable (ModelValidator ensures this), but these are nullable on IMutableSkipNavigation and IConventionSkipNavigation. Seems like a pretty satisfactory solution, no?
  • IPropertyBase.ClrType is nullable (because of skip navigations), but IProperty overrides it to be non-nullable.
  • Changes a bit of query too (/cc @smitpatel)

Part of #19007

@roji roji linked an issue Oct 30, 2020 that may be closed by this pull request
23 tasks
src/EFCore/Metadata/Internal/ForeignKey.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Internal/Navigation.cs Outdated Show resolved Hide resolved
src/EFCore/Extensions/PropertyExtensions.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Internal/ForeignKey.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Internal/ForeignKey.cs Show resolved Hide resolved
src/EFCore/Metadata/Internal/ForeignKey.cs Outdated Show resolved Hide resolved
{
_typeMapping = typeMapping;
// TODO-NULLABLE: null check conflicts with [NotNull] annotation above, which seems like it may be incorrect.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotation is correct, the check should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasTypeMapping should also have [NotNull] and callers should add a check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no way to unset a type mapping, right? Making sure because the docs on HasTypeMapping explicitly document accepting null to remove type mapping.

The only usage in our codebase seems to be in TypeMappingConvention.ProcessModelFinalizing, which we'll annotate a bit later - should that throw if FindMapping returns null?

In the meantime, changed HasTypeMapping (and CanHasTypeMapping) to have [NotNull].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will likely obsolete these methods when #22031 is done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndriySvyryd as pointed by @smitpatel in #23147 (comment), SetTypeMapping returns CoreTypeMapping but that isn't documented. Since the parameter is now [NotNull], it seems they only ever return the supplied parameter. So these can probably be changed to return void, but if you're planning to obsolete them anyway for 6.0...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can say that it returns the type mapping that was set

src/EFCore/Metadata/Internal/ServiceProperty.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Internal/SkipNavigation.cs Outdated Show resolved Hide resolved
src/EFCore/Metadata/Internal/SkipNavigation.cs Outdated Show resolved Hide resolved
@roji
Copy link
Member Author

roji commented Oct 30, 2020

@smitpatel addressed your comments

@@ -88,7 +90,7 @@ public static IEnumerable<IConventionKey> GetContainingKeys([NotNull] this IConv
/// <param name="property"> The property. </param>
/// <param name="typeMapping"> The <see cref="CoreTypeMapping" /> for this property. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static CoreTypeMapping SetTypeMapping(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method missing in XML docs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean in the published docs? I think this is a new method in 5.0 so not yet published, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In XML docs in source code. The method is not void but still does not specify tag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, will fix this in the next nullability PR, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this now always returns the provided parameter (#23147 (comment)), I'm embarrassed to document the return type as "always identical to the parameter" :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too we can say that it returns the type mapping that was set

@ghost
Copy link

ghost commented Oct 31, 2020

Hello @roji!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Annotates Model, Property, Navigation, Key, Index, and all their extensions.

Part of #19007
@ghost ghost merged commit 319db8b into main Oct 31, 2020
@ghost ghost deleted the MoreMetadataNullability branch October 31, 2020 17:57
This pull request was closed.
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.

Annotate EF Core for nullable reference types
3 participants