-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
CurrentTenantProvider called even when table has no tenantId column specified #2623
Comments
Reproduced and got a fix in that linked PR. Effectively the query should only get the current tenantId IF we are using a DataSourceProvider that actually needs it (like DataSource per tenant, Schema per tenant etc). In this case I'm 99% sure its TenantMode.PARTITION (aka tenant_id column in the tables). That means it's using the Not sure if I'm explained that well, might be easier to look at the diff in the PR :) |
Yes I understand! Thank you for getting back to me so quickly. I am using TenantMode.PARTITION, so you are correct. One final question here on the topic. If the non-tenant entity were to reference an entity that had a tenant ID...for example: @Entity
@Table(name = "no-tenant")
public class NoTenantEntity extends Base {
@NotNull
private String name;
@OneToMany
private List<UserEntity> users;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
...additional getters and setters for users....
} Would a query getitng the non-tenant entity always return an empty list of users unless you call the non-tenant entity as a logged in user (thus having a tenant id to reference)? |
A query for a non-tenant entity means that there is no Reference: https:/ebean-orm/ebean/blob/master/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java#L1121 ... the tenant BeanProperty is null ... so
It would be a full list of related users. So a query like: new QNoTenantEntity()
.users.fetch() // fetch associated entities that happen to have a @TenantId property
.findList(); The query will execute without a That is, in a multi-tenant app, often there are parts of the application are kind of "global" (not partitioned by tenant). When we query these non-tenant entities it is expected to be app code that is doing "global" things and not "per tenant" things. For example, some global admin function looking at all the users across all tenants. |
…vider #2623 - CurrentTenantProvider called even when table has no tenantId column specified
That makes sense. Thank you! |
Expected behavior
Based on the class structure below, I thought this query would not call the current tenant provider:
Actual behavior
The current tenant provider is called
Steps to reproduce
This is an issue since certain calls to my database are non-tenant specific based on the table they are accessing. I can get around it by setting a fake user context, but that seemed like a hacky answer since no logged in user is calling the database. Thank you in advance!
The text was updated successfully, but these errors were encountered: