You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When loading entities with the same ID from two tenants, same entity is returned - the one from the first tenant. It appears that when dispatching a switch event, TenantEntityManager's identity map is not cleared, so all entities that were loaded while working with the first tenant remain. This means that, if entities with same IDs are requested from the tenant entity manager, the existing ones - from the previous tenant - will get returned. Example:
$switchEvent = new SwitchDbEvent(1);
$dispatcher->dispatch($switchEvent);
$product = $tem->getRepository(Product::class)->find(3);
$switchEvent = new SwitchDbEvent(2);
$dispatcher->dispatch($switchEvent);
$product2 = $tem->getRepository(Product::class)->find(3);
Both $product1 and $product2 are returned as the same product, even though they are completely different in the two databases. I can get around this by calling $tem->clear() after dispatching a switch event, but I feel that this should happen automatically. Can't see any circumstances where keeping entities of frist tenant cached around while working with another tenant would be useful (and not dangerous instead).
The text was updated successfully, but these errors were encountered:
skarnl
added a commit
to skarnl/multi_tenancy_bundle
that referenced
this issue
Sep 4, 2024
I had the same issue, found this opened issue, so linked here in my PR ;)
knezmilos13
changed the title
TenantEntityManager keeps returns entity of previous tenant after swtiching DB - identity map not cleared?
TenantEntityManager returns entity of previous tenant after swtiching DB - identity map not cleared?
Sep 5, 2024
When loading entities with the same ID from two tenants, same entity is returned - the one from the first tenant. It appears that when dispatching a switch event, TenantEntityManager's identity map is not cleared, so all entities that were loaded while working with the first tenant remain. This means that, if entities with same IDs are requested from the tenant entity manager, the existing ones - from the previous tenant - will get returned. Example:
Both $product1 and $product2 are returned as the same product, even though they are completely different in the two databases. I can get around this by calling
$tem->clear()
after dispatching a switch event, but I feel that this should happen automatically. Can't see any circumstances where keeping entities of frist tenant cached around while working with another tenant would be useful (and not dangerous instead).The text was updated successfully, but these errors were encountered: