Skip to content

Commit 20ea1f8

Browse files
Document the migration-vs-command tag-seeding lesson from PR #12
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016i9S7LQsCL3FGaih3ZTRBJ
1 parent a601edc commit 20ea1f8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ only) for deployment, hosting, and domain specifics.
5858
- [`docs/lessons.md`](docs/lessons.md) — terse, reusable cross-session
5959
lessons (CI vs. local venv trust, worktree port collisions, debug-color
6060
verification, cyclic-animation sampling, verifying cross-session claims,
61-
ES mapping drift, test-factory isolation, sticky/overflow CSS gotchas).
61+
ES mapping drift, test-factory isolation, sticky/overflow CSS gotchas,
62+
migration-vs-command tag seeding).
6263
- [`docs/features/image-cdn.md`](docs/features/image-cdn.md) — the Worker +
6364
R2 bucket image CDN.
6465
- [`docs/features/pdf-generator.md`](docs/features/pdf-generator.md) — PDF

docs/lessons.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,24 @@ artifact in a real browser (Chromium at
184184
`executablePath: /opt/pw-browsers/chromium`; default Playwright download is
185185
absent). State clearly in the report that live behavior itself was not
186186
observed.
187+
188+
## Seeding `Tag` rows via a data migration breaks tests that assert on the whole table — use a management command instead
189+
190+
Tried seeding six new `Tag` rows via a Django data migration (RunPython).
191+
Broke 5 unrelated tests (`test_views.py::TestGetTags::*`,
192+
`test_tag_votes.py::TestPostTagConsensus::test_returns_an_entry_for_every_seeded_tag`)
193+
because they assert the _complete_ `Tag` table is empty in a fresh DB
194+
(besides the synthetic, never-persisted `"NSFW"` pseudo-tag from
195+
`cardpicker/tags.py`) — a migration runs unconditionally at DB-setup time,
196+
including the test database, so any migration-seeded row becomes
197+
permanent baseline state for every test in the suite, not just the ones
198+
that care about it. The repo's existing 13-tag `DEFAULT_TAGS` taxonomy
199+
(`cardpicker/default_tags.py`) is deliberately _not_ wired into any
200+
migration for exactly this reason — it's a manual, idempotent
201+
`seed_default_tags` management command only. Any future tag/taxonomy
202+
seeding should follow that same pattern (a `..._tags.py` module +
203+
`get_or_create` + a thin management-command wrapper), never a migration,
204+
regardless of how the request is phrased ("data migration" in a task spec
205+
should be read as "a repeatable seeding step," not literally
206+
`migrations.RunPython`, when the target table has DB-wide list-all
207+
consumers).

0 commit comments

Comments
 (0)