Skip to content

fix(seed): coerce every *_date field, not just release_date - #49

Merged
Seungpyo1007 merged 1 commit into
mainfrom
fix/seed-date-coercion
Jul 30, 2026
Merged

fix(seed): coerce every *_date field, not just release_date#49
Seungpyo1007 merged 1 commit into
mainfrom
fix/seed-date-coercion

Conversation

@Seungpyo1007

Copy link
Copy Markdown
Member

Bug

_load_dir converted ISO date strings by field name:

if isinstance(record.get("release_date"), str):
    record["release_date"] = date.fromisoformat(record["release_date"])

So a category whose date column is named anything else reached SQLite as a str. Seeding the new data/website tree (#48) died on the first insert:

TypeError: SQLite Date type only accepts Python date objects as input
[SQL: INSERT INTO website (slug, name, homepage_url, launch_date, ...)]

Coercion now keys on the _date suffix, so launch_date — and any future category's date column — works without another special case.

Why the existing tests missed it

Every category's endpoint tests insert their fixture through the model, passing a real date object:

session.add(Software(..., release_date=date(1998, 1, 2)))

That never exercises the JSON → DB path where this conversion happens, which is why #48 passed CI with the bug in it. tests/unit/test_seed_date_coercion.py covers that path now: a *_date field is converted, a non-date field is left alone, and a missing directory stays empty.

Verification

  • pytest tests/unit/test_seed_date_coercion.py3 passed
  • Seeded the real 40,084-record data/website tree end to end: SEED OK: {'websites': 40084} (it failed on record 1 before)
  • ruff check app tests ✅ · mypy app

Follow-up to #48; the TechAPI data PR is blocked on this.

_load_dir turned "release_date" strings into date objects by name, so a
category whose date column is named differently reached SQLite as a str:
seeding data/website failed with

  TypeError: SQLite Date type only accepts Python date objects as input

on website.launch_date. Coercion now keys on the _date suffix.

The endpoint tests for each category insert fixtures through the model with
real date objects, so none of them covered the JSON -> DB path where this
happens; test_seed_date_coercion.py now does.

Verified by seeding the 40,084-record data/website tree: 40,084 rows inserted.
@Seungpyo1007
Seungpyo1007 merged commit 897cc01 into main Jul 30, 2026
1 check passed
@Seungpyo1007
Seungpyo1007 deleted the fix/seed-date-coercion branch July 30, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant