Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TenantEntityManager returns entity of previous tenant after swtiching DB - identity map not cleared? #50

Open
knezmilos13 opened this issue Aug 22, 2024 · 1 comment

Comments

@knezmilos13
Copy link

knezmilos13 commented Aug 22, 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:

$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).

skarnl added a commit to skarnl/multi_tenancy_bundle that referenced this issue Sep 4, 2024
@skarnl
Copy link

skarnl commented Sep 4, 2024

I had the same issue, found this opened issue, so linked here in my PR ;)

@knezmilos13 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
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

No branches or pull requests

2 participants