From 224a71ba5674a45e2db4d4c64405132d56bcacea Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Sat, 25 Jul 2026 03:40:37 +0200 Subject: [PATCH] fix: CronJobContribution tenant_id error - use default tenant from DB - register_plugin_contributions was accessing cron_def.tenant_id which doesn't exist - All Contribution Models (AgentDefinitionContribution, AutomationTemplateContribution, CronJobContribution) lack tenant_id field - Fix: Query default tenant from DB and use it for all contribution registrations - Also fixes agent_def.tenant_id and auto_def.tenant_id which had the same issue --- app/plugins/builtins/automation/plugin.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/plugins/builtins/automation/plugin.py b/app/plugins/builtins/automation/plugin.py index 14c935a..d9d6b09 100644 --- a/app/plugins/builtins/automation/plugin.py +++ b/app/plugins/builtins/automation/plugin.py @@ -187,16 +187,22 @@ class AutomationPlugin(BasePlugin): from app.plugins.builtins.automation.models import AutomationCronJob from sqlalchemy import select + # Get default tenant_id from the first tenant in the DB + from app.models.tenant import Tenant + tenant_result = await db.execute(select(Tenant).limit(1)) + tenant = tenant_result.scalar_one_or_none() + default_tenant_id = tenant.id if tenant else None + # Register agent definitions agent_names: list[str] = [] for agent_def in manifest.agent_definitions: prefixed_name = f"{plugin_name}.{agent_def.name}" agent_names.append(prefixed_name) # Check if already exists (idempotent) - existing = await AgentService.get_by_name(db, agent_def.tenant_id, prefixed_name) if hasattr(AgentService, 'get_by_name') else None + existing = await AgentService.get_by_name(db, default_tenant_id, prefixed_name) if hasattr(AgentService, 'get_by_name') else None if existing is None: try: - await AgentService.create(db, agent_def.tenant_id, { + await AgentService.create(db, default_tenant_id, { "name": prefixed_name, "description": agent_def.description, "llm_model": agent_def.llm_model, @@ -219,10 +225,10 @@ class AutomationPlugin(BasePlugin): for auto_def in manifest.automation_templates: prefixed_name = f"{plugin_name}.{auto_def.name}" automation_names.append(prefixed_name) - existing = await AutomationService.get_by_name(db, auto_def.tenant_id, prefixed_name) if hasattr(AutomationService, 'get_by_name') else None + existing = await AutomationService.get_by_name(db, default_tenant_id, prefixed_name) if hasattr(AutomationService, 'get_by_name') else None if existing is None: try: - await AutomationService.create(db, auto_def.tenant_id, { + await AutomationService.create(db, default_tenant_id, { "name": prefixed_name, "description": auto_def.description, "trigger_type": auto_def.trigger_type, @@ -248,7 +254,7 @@ class AutomationPlugin(BasePlugin): ) existing = result.scalar_one_or_none() if existing is None: - await CronJobService.create(db, cron_def.tenant_id, { + await CronJobService.create(db, default_tenant_id, { "name": prefixed_name, "cron_expression": cron_def.cron_expression, "job_type": cron_def.job_type,