Skip to content

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

Closed

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.

Activity

  1. added a commit that references this issue on Mar 26, 2026
    be2cc05
  2. iammukeshm commented on Mar 26, 2026

    @iammukeshm
    Member

    Thanks for the report @fernando-santillana — good catch.

    The missing base.OnModelCreating() call is confirmed. One clarification: AuditRecord doesn't implement ISoftDeletable, so the soft-delete filter concern doesn't apply here. However, the multi-tenant isolation risk is real — without the base call, Finbuckle's MultiTenantDbContext.OnModelCreating() never activates the .IsMultiTenant() configuration into actual query filters.

    Fixed in #1228.

  3. added a commit that references this issue on May 1, 2026
    eaff267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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