diff --git a/app/plugins/builtins/automation/plugin.py b/app/plugins/builtins/automation/plugin.py index fc6c33a..afb6e6c 100644 --- a/app/plugins/builtins/automation/plugin.py +++ b/app/plugins/builtins/automation/plugin.py @@ -248,13 +248,16 @@ class AutomationPlugin(BasePlugin): from sqlalchemy import select as sa_select # Get first tenant + admin user for seeding - from app.models.user import User + from app.models.user import User, UserTenant from app.models.tenant import Tenant tenant_result = await db.execute(sa_select(Tenant).limit(1)) tenant = tenant_result.scalar_one_or_none() if tenant: user_result = await db.execute( - sa_select(User).where(User.tenant_id == tenant.id).limit(1) + sa_select(User) + .join(UserTenant, UserTenant.user_id == User.id) + .where(UserTenant.tenant_id == tenant.id) + .limit(1) ) user = user_result.scalar_one_or_none() if user: