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

False positive global query filter warning for owned entities #26900

Closed
collinbarrett opened this issue Dec 5, 2021 · 0 comments · Fixed by #28858
Closed

False positive global query filter warning for owned entities #26900

collinbarrett opened this issue Dec 5, 2021 · 0 comments · Fixed by #28858
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@collinbarrett
Copy link

As mentioned here and similar to here, it seems like we may be getting a false positive global query filter warning (PossibleIncorrectRequiredNavigationWithQueryFilterInteractionWarning) for owned entities whose owners have a global filter query configured. Since, as far as I can tell, owned entities cannot be queried directly (apart from going through their owner) and they cannot have global query filters themselves, maybe we should not show this warning in this scenario.

Sample Code

using Microsoft.EntityFrameworkCore;

public class TestContext : DbContext
{
    public TestContext(DbContextOptions<TestContext> options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Blog>(
            e =>
            {
                e.HasQueryFilter(b => !b.IsDeleted);
                e.OwnsMany(b => b.Posts);
            });
    }
}

public class Blog
{
    public int BlogId { get; set; }
    public bool IsDeleted { get; set; }
    public ICollection<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public int BlogId { get; set; }
    public string Content { get; set; }
    public bool IsDeleted { get; set; }
    public Blog Blog { get; set; }
}

Include stack traces

N/A

Include verbose output

dotnet ef migrations add Test
Build started...
Build succeeded.
warn: 12/05/2021 08:26:55.418 CoreEventId.PossibleIncorrectRequiredNavigationWithQueryFilterInteractionWarning[10622] (Microsoft.EntityFrameworkCore.Model.Validation)
      Entity 'Blog' has a global query filter defined and is the required end of a relationship with the entity 'Post'. This may lead to unexpected results when the required entity is filtered out. Either configure the navigation as optional, or define matching query filters for both entities in the navigation. See https://go.microsoft.com/fwlink/?linkid=2131316 for more information.
warn: 12/05/2021 08:26:55.424 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure)
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
info: 12/05/2021 08:26:55.607 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
      Entity Framework Core 6.0.0 initialized 'TestContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL:6.0.0+025fc55189ae41e3f2b98bcbe4eb44c505653700' with options: SensitiveDataLoggingEnabled MaxPoolSize=1024 MigrationsAssembly=FilterLists.Directory.Infrastructure.Migrations using snake-case naming  (culture=)
warn: 12/05/2021 08:26:55.629 CoreEventId.PossibleIncorrectRequiredNavigationWithQueryFilterInteractionWarning[10622] (Microsoft.EntityFrameworkCore.Model.Validation)
      Entity 'Blog' has a global query filter defined and is the required end of a relationship with the entity 'Post'. This may lead to unexpected results when the required entity is filtered out. Either configure the navigation as optional, or define matching query filters for both entities in the navigation. See https://go.microsoft.com/fwlink/?linkid=2131316 for more information.
Done. To undo this action, use 'ef migrations remove'

Include provider and version information

EF Core version: 6.0.0
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: net6.0
Operating system: Windows 10
IDE: Visual Studio 2022

@maumar maumar self-assigned this Dec 6, 2021
@ajcvickers ajcvickers added this to the 7.0.0 milestone Dec 9, 2021
@smitpatel smitpatel assigned smitpatel and unassigned maumar Aug 23, 2022
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed needs-design propose-punt labels Aug 23, 2022
smitpatel added a commit that referenced this issue Aug 23, 2022
smitpatel added a commit that referenced this issue Aug 24, 2022
@smitpatel smitpatel modified the milestones: 7.0.0, 7.0.0-rc2 Aug 29, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-rc2, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants