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
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user