Skip to content

Add tests for partitioned multi-tenant child queries#4161

Closed
erdtsieck wants to merge 1 commit intoJasperFx:masterfrom
erdtsieck:bugfix/fix-hash-partitioned-multi-tenant-child-queries
Closed

Add tests for partitioned multi-tenant child queries#4161
erdtsieck wants to merge 1 commit intoJasperFx:masterfrom
erdtsieck:bugfix/fix-hash-partitioned-multi-tenant-child-queries

Conversation

@erdtsieck
Copy link
Contributor

Add tests to verify querying within nested/child collections is correctly scoped per tenant when using partitioning. Updates in:

  • src/CoreTests/Partitioning/partitioning_configuration.cs: add Marten using and new test cannot_query_within_child_collections_across_partition_tenants which seeds targets with nested objects in two tenants and asserts queries return only tenant-specific results.
  • src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs: add several usings (Collections.Generic, Diagnostics, Marten.Linq), initialize nested objects for test fixtures, and add cannot_query_within_child_collections_across_tenants with similar assertions.

These tests ensure child-collection Any() queries are correctly limited to the active tenant/partition.

Add tests to verify querying within nested/child collections is correctly scoped per tenant when using partitioning. Updates in:

- src/CoreTests/Partitioning/partitioning_configuration.cs: add Marten using and new test cannot_query_within_child_collections_across_partition_tenants which seeds targets with nested objects in two tenants and asserts queries return only tenant-specific results.
- src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs: add several usings (Collections.Generic, Diagnostics, Marten.Linq), initialize nested objects for test fixtures, and add cannot_query_within_child_collections_across_tenants with similar assertions.

These tests ensure child-collection Any() queries are correctly limited to the active tenant/partition.
jeremydmiller added a commit that referenced this pull request Mar 8, 2026
…tables

DocumentMapping.TenancyStyle was only synced to QueryMembers.TenancyStyle
once during the constructor, before builder alterations ran. When tenancy
was configured via Schema.For<T>().MultiTenantedWithPartitioning(), the
builder set TenancyStyle after construction, so QueryMembers kept the
default Single value. This caused SubQueryFilter to skip adding the
tenant_id filter to the outer query, allowing ctid collisions across
partitions to return rows from other tenants.

Fix: make DocumentMapping.TenancyStyle setter always sync to
QueryMembers.TenancyStyle. Add regression tests for both hash and list
partitioning. Closes GH-4161.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant