Skip to content

Bug: AuditDbContext.OnModelCreating() does not call base.OnModelCreating() #1226

@fernando-santillana

Description

@fernando-santillana

Description

AuditDbContext.OnModelCreating() does not call base.OnModelCreating(modelBuilder), which means the soft-delete global query filter and Finbuckle multi-tenant
filters defined in BaseDbContext are never applied to audit records.

Location

src/Modules/Auditing/Modules.Auditing/Persistence/AuditDbContext.cs

Current code

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    ArgumentNullException.ThrowIfNull(modelBuilder);
    modelBuilder.ApplyConfigurationsFromAssembly(typeof(AuditDbContext).Assembly);
    // ← missing base.OnModelCreating(modelBuilder)
}

Expected code

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    ArgumentNullException.ThrowIfNull(modelBuilder);
    modelBuilder.ApplyConfigurationsFromAssembly(typeof(AuditDbContext).Assembly);
    base.OnModelCreating(modelBuilder);
}

Impact

BaseDbContext.OnModelCreating() applies a global query filter for soft-delete:

modelBuilder.AppendGlobalQueryFilter<ISoftDeletable>(s => !s.IsDeleted);

And BaseDbContext inherits from Finbuckle's MultiTenantDbContext, whose OnModelCreating configures multi-tenant query filters.

Without the base call:
1. Soft-deleted audit records are still returned by queries (the ISoftDeletable filter is not applied)
2. Multi-tenant isolation is broken for audit data — a tenant could potentially see audit records from other tenants

Fix

One-line addition: base.OnModelCreating(modelBuilder); at the end of the method override.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions