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

Debug messages intended for shadow properties should not be logged for indexer properties #33488

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ protected virtual void ValidateNoShadowKeys(
{
foreach (var key in entityType.GetDeclaredKeys())
{
if (key.Properties.Any(p => p.IsImplicitlyCreated())
if (key.Properties.Any(p => p.IsShadowProperty())
&& ConfigurationSource.Convention.Overrides(key.GetConfigurationSource())
&& !key.IsPrimaryKey())
{
Expand Down Expand Up @@ -1275,7 +1275,8 @@ protected virtual void LogShadowProperties(
{
foreach (var property in entityType.GetDeclaredProperties())
{
if (property.IsImplicitlyCreated())
if (property.IsShadowProperty()
&& property.GetConfigurationSource() == ConfigurationSource.Convention)
{
var uniquifiedAnnotation = property.FindAnnotation(CoreAnnotationNames.PreUniquificationName);
if (uniquifiedAnnotation != null
Expand Down
15 changes: 15 additions & 0 deletions test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ public virtual void Passes_on_shadow_primary_key_created_by_convention_in_depend
.GenerateMessage("A", "Key"), modelBuilder, LogLevel.Debug);
}

[ConditionalFact] // Issue #33484
public virtual void Does_not_log_for_shadow_property_when_creating_indexer_property()
{
var modelBuilder = CreateConventionlessModelBuilder();
var model = (IConventionModel)modelBuilder.Model;

var entityType = model.AddEntityType("Bag", typeof(Dictionary<string, object>))!;
entityType.SetIsKeyless(true);
entityType.AddIndexerProperty("Foo", typeof(int));

VerifyLogDoesNotContain(
CoreResources.LogShadowPropertyCreated(new TestLogger<TestLoggingDefinitions>())
.GenerateMessage("Bag (Dictionary<string, object>)", "Foo"), modelBuilder);
}

[ConditionalFact]
public virtual void Warns_on_uniquified_shadow_key_due_to_wrong_type()
{
Expand Down
Loading