marten icon indicating copy to clipboard operation
marten copied to clipboard

WriteArray method doesn't honor multi-tenancy

Open dgrozenok opened this issue 2 years ago • 0 comments

  1. Setup the Marten document store with _.Policies.AllDocumentsAreMultiTenanted();
  2. Store several documents with a specific tenantId.
  3. In the aspnet core web api action open the query session with that tenantId and use WriteArray() method like this:
app.MapGet("/{tenantId}/product", (string tenantId, [FromServices] IDocumentStore store, HttpContext context) =>
    store.QuerySession(tenantId).Query<ProductListProduct>().Take(10).WriteArray(context)
);

The query generated looks like this:

select d.data from public.mt_doc_productlistproduct as d where d.tenant_id = :tenantid LIMIT :p1
  tenantid:
  p1: 10

As a result the empty array is returned. Note the empty tenantId.

  1. If instead of WriteArray() to use ToList() the query generated as this
select d.data from public.mt_doc_productlistproduct as d where d.tenant_id = :tenantid LIMIT :p1
  tenantid: 5c3d2c5c71796847c037c41b
  p1: 10

And the 10 documents array is returned.

dgrozenok avatar Aug 01 '22 17:08 dgrozenok