Skip to content

feat(demos): add polymorphic-cms demo with single-table inheritance - #232

Open
fruch with Copilot wants to merge 4 commits into
masterfrom
copilot/demos-create-polymorphic-cms-demo
Open

feat(demos): add polymorphic-cms demo with single-table inheritance#232
fruch with Copilot wants to merge 4 commits into
masterfrom
copilot/demos-create-polymorphic-cms-demo

Conversation

Copilot AI commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
  • Check GitHub Actions CI failure logs
  • Identify ruff format issues in demos/polymorphic-cms/seed.py
  • Fix quote style in f-string (line 242)
  • Collapse multi-line string to single line (lines 277-280)
  • Verify ruff format + ruff check pass

Copilot AI requested a review from fruch April 15, 2026 18:05
@fruch
fruch marked this pull request as ready for review April 15, 2026 20:28
Content.sync_table() only creates columns defined on the base Content
class. Subclass-specific columns (body, word_count, video_url, etc.)
are never added to the Cassandra table, causing 'Unknown identifier'
errors at runtime when saving subclass instances.

Call sync_table() on each subclass after the base class so the driver
issues ALTER TABLE ADD for the missing columns.

@fruch fruch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — Polymorphic CMS Demo

Summary

Well-structured demo that effectively showcases coodie's single-table inheritance via Discriminator. The code follows established demo conventions (file structure, Makefile targets, seed script patterns, FastAPI lifespan) and the HTMX UI is nicely themed.

Bug Fix (pushed)

Content.sync_table() does not create subclass-specific columns.

build_schema(Content) uses get_type_hints(Content) which only returns Content's own fields. Subclass columns like body, word_count, video_url, duration_seconds, resolution, audio_url, and episode_number are never added to the Cassandra table. When saving any subclass instance, the INSERT includes these columns and Cassandra returns Unknown identifier body.

Fix: call sync_table() on each subclass after the base class — the driver's sync_table issues ALTER TABLE ADD for columns present in the model but missing from the table. Pushed as commit 1d205e9.

Note: This arguably warrants a framework-level enhancement — sync_table() on a polymorphic base could automatically discover and sync all registered subclasses. Worth tracking as a separate issue.

Minor Observations

  1. seed.py line 234-236 — The fallback disc = type(item).__name__.lower() should never trigger since coodie auto-injects the discriminator value on save(). Not harmful, but the defensive check is unnecessary.

  2. Demo README — The How It Works section shows the model definitions clearly. Good onboarding for users learning about Discriminator.

Verdict

✅ Good to merge after CI passes on the fix commit. The demo is well-crafted and the only blocking issue (the sync_table bug) has been fixed.

…rent cache

_schema() used hasattr() which traverses MRO, causing subclasses to
return the parent's cached schema instead of building their own. This
meant subclass-specific columns (e.g. body, word_count) were never
included in sync_table() ALTER TABLE ADD statements.

Aligns with the same __dict__ guard already used in build_schema().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants