fix(tasks): write slug+owner on task create, accept either id or slug#63
Merged
Conversation
Production tasks table has NOT NULL slug and owner columns (added externally from the unmerged staging refactor 472d4b7), but main's POST /tasks insert omits them — every public task create has been failing with NotNullViolation. The published 0.2.6.dev1 CLI also sends slug instead of id, so requests are 422'd by FastAPI before reaching the DB. - POST /tasks: accept id and/or slug as form fields, normalize to one task_id, insert (id, slug=task_id, owner='hive', ...). - _sync_tasks_from_github: insert slug+owner. - POST /tasks/private: insert slug+owner (owner=str(user_id) for per-user namespace). - db.py: add idempotent migration that ADD COLUMN slug/owner if missing (gated on information_schema). No-op on prod where they already exist. CLI is intentionally untouched — server now accepts both shapes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /tasksaccepts bothidandslugform fields, normalizes to onetask_id, and now writesslug+owner='hive'into the row._sync_tasks_from_githubandPOST /tasks/privatealso writeslug+owner(private usesowner=str(user_id)).ADD COLUMN slug/ownerontaskswhen missing — no-op on prod where they already exist.Why
Production's
taskstable hasslug NOT NULLandowner NOT NULLcolumns (added externally from the unmerged staging refactor 472d4b7), butmain's INSERTs don't supply them. Every publicPOST /tasksand every_sync_tasks_from_githubinsert has been failing withpsycopg.errors.NotNullViolation: null value in column "slug"— visible repeatedly in prod logs. Repo gets created on GitHub, then the DB row never lands, so the task is never registered. Separately, the published0.2.6.dev1CLI sends onlyslug(it was cut from a slug-aware branch), which the oldid-only signature rejects with 422 before reaching the DB.This patch is a compatibility bridge until the full owner/slug refactor merges from staging. CLI is intentionally untouched — accepting either field on the server unblocks all current clients.
Migration safety
Additive + idempotent. Each
ALTERis gated on aninformation_schema.columnscheck;slugis backfilled (UPDATE tasks SET slug = id WHERE slug IS NULL) beforeSET NOT NULL;ownergets aDEFAULT 'hive'so existing rows satisfy NOT NULL immediately. On prod (where both columns already exist) the entire block is a no-op. No DROP, no type change, no destructive DDL.Test plan
slug,ownercleanly.slug/owner(or run the same boot twice) → migration skipped, no error.curl -F id=foo -F name=Foo -F description=... -F archive=@t.tar.gz /api/tasks→ 201, row visible intaskswithslug='foo',owner='hive'.curl -F slug=bar ...(noid) → 201, row inserted withid=slug='bar'.curlwith neitheridnorslug→ 400 "id (or slug) is required".curl -X POST /api/tasks/sync→ discoveredtask--*repos register without NotNullViolation in PG logs.POST /api/tasks/privatewith a real user GitHub repo → row inserted withslug=task_id,owner=str(user_id).🤖 Generated with Claude Code