fix: stale numbers and slug reassignments

This commit is contained in:
Alex committed 2026-06-14 14:24:18 +01:00
1 parent 1342cb30d3
commit ab3337ced8
2 files changed
+7 -2

No files matched your search

@@ -751,6 +751,11 @@ def apply_import(conn, user: str, doc: dict, resolution: Optional[dict] = None)
agents_repo = AgentsRepository(conn)
is_update = bool(target.get("action") == "update" and target.get("agent_id"))
exclude_id = str(target["agent_id"]) if is_update else None
# Slug is recomputed from the file, not preserved from the matched row:
# a round-tripped export carries metadata.slug so it stays stable, but an
# update-by-id whose file omits the slug and renames the agent rewrites the
# slug to follow the new name (excluding the row's own slug from collision
# checks). Intended — the slug tracks the file.
slug = _unique_slug(agents_repo, user, metadata.get("slug") or spec.get("name"), exclude_id=exclude_id)
try:
+2 -2
View File
@@ -207,7 +207,7 @@ agents_table = Table(
Column("key", CITEXT, unique=True),
# Stable per-user human identifier used to match an agent across
# YAML export/import (idempotent re-import / GitOps). Uniqueness is
# enforced by a partial unique index in migration 0018, not here, so
# enforced by a partial unique index in migration 0019, not here, so
# multiple agents may carry NULL.
Column("slug", CITEXT),
Column("image", Text),
@@ -238,7 +238,7 @@ agents_table = Table(
)
# Per-user uniqueness of the export/import slug. Mirrors the partial unique
# index created in migration 0018 so a schema built from this metadata
# index created in migration 0019 so a schema built from this metadata
# (e.g. create_all) matches an Alembic-built one.
Index(
"ix_agents_user_slug",