Skip to content

Content-type taxonomy and the v2 /pages article filter (AISD-124)

Problem

The public v2 store served /pages/{slug} by filtering content.content_type == "article". No article type exists in the deployed content_types lookup -- the seed only carries homepage_article and quiz. So every real article 404'd, even though the row was published and active. This is a data/query mismatch in cms-api, not schema drift: hq.cms.db check reports the live stage schema in sync with the models.

Options considered

Option A -- add/rename an article type in content_types (rejected)

Add (or rename to) a literal article type in the content_types lookup via an hq/sql_models DDL change, then point the query at it.

Rejected: it rewrites a column that existing content rows, content_history snapshots, and the content_types seed already depend on. It is multi-repo (an hq DDL + a cms-api query change), carries the highest blast radius (a backfill of every content row's content_type), and buys nothing the cheaper options do not. A rename is the expensive failure mode for a problem that is purely a query constant.

Option B -- point the query at the existing homepage_article (viable)

Change the single literal from "article" to "homepage_article". Correct and minimal, but it re-hardcodes a bare string in two stores (SQL + memory) and silently couples them: the next article-like type (say a future evergreen_article) needs another two-store edit, and the memory store can drift from the SQL store again (the AISD-116 lesson: tests run against the memory store, so a wrong literal there passes tests while prod 404s).

Option C -- centralized ARTICLE_CONTENT_TYPES constant (recommended, implemented)

Introduce one constant ARTICLE_CONTENT_TYPES: tuple[str, ...] = ("homepage_article",) in cms_api/public/store/v2_common.py (the module both stores already import for shared shaping). Both article queries filter content_type IN ARTICLE_CONTENT_TYPES:

  • SqlPublicStore._content_by_slug -> Content.content_type.in_(ARTICLE_CONTENT_TYPES)
  • SqlPublicStore._related_articles -> adds Content.content_type.in_(ARTICLE_CONTENT_TYPES)
  • MemoryPublicStore._published_article -> item.content_type not in ARTICLE_CONTENT_TYPES
  • MemoryPublicStore._related_v2 -> adds the same in filter

Adding a future article-like type is a one-line change to the tuple, no DB rename is ever needed, and the two stores cannot drift because they share the constant. No hardcoded "article" literal remains in any v2 query.

trending as a structural article type (AISD-196)

trending was added to ARTICLE_CONTENT_TYPES -- ("homepage_article", "trending") -- so a content.content_type == "trending" row is served by /pages/{slug} (and is eligible as a related candidate) exactly like a homepage_article row. This is the one-line tuple extension anticipated above; no other query, DDL, or per-store change was required.

trending (the content_type) and is_trending (the boolean flag) are deliberately independent axes:

  • content_type = "trending" decides whether the row is served as an article by /pages -- it is a structural/taxonomy classification, analogous to homepage_article or quiz.
  • is_trending (bool) decides whether the row appears in the /lists?kind=trending feed -- a per-item flag, unrelated to content_type, that can be set on any content type (see "/lists and /sitemap stay flag/category-based" above).

So all four combinations are valid and independent: a homepage_article can be is_trending=True (shows in the trending feed, served as a normal article page), a trending-typed row can have is_trending=False (served as an article page, absent from the trending feed), and so on. Neither field implies the other.

This is also distinct from the Trending category (a content_categories taxonomy entry): a category is an editorial grouping surfaced via kind=category, orthogonal to both content_type and is_trending. A trending-typed article need not carry the Trending category, and an article in the Trending category need not be content_type="trending" or is_trending=True.

Worker surface -> DB content_type map

The AISD-115 worker renders three surfaces. They map to the DB content_types lookup as follows:

Worker surface DB content_type(s) v2 endpoint
Article page homepage_article, trending (ARTICLE_CONTENT_TYPES) /pages/{slug}
Quiz quiz (not served by /pages; its own surface)
Static page template page elements (/settings.templates) /settings (template blocks)

Only the types in ARTICLE_CONTENT_TYPES are served as articles by /pages. A quiz slug returns 404 from /pages by design; quizzes are a separate surface.

/lists and /sitemap stay flag/category-based (explicit decision)

/lists (kind = homepage / featured / trending / category / author / recent / related / search) and /sitemap select by flags (show_in_homepage, is_featured, is_trending), category/author membership, or "all published", and legitimately surface any flagged content regardless of type. They are deliberately NOT filtered to ARTICLE_CONTENT_TYPES: a flagged quiz on the homepage is intended, not an oversight. Only the article-specific surfaces (/pages and an article's related list) apply the article-type filter.

Stored media path contract with AISD-115 (/cmp-media/)

The media repopulation tooling (scripts/repopulate_media.py, Part B of this task) ingests external images into the private cms-media S3 bucket and rewrites the DB references. The stored value is a worker-relative path, never an absolute or presigned S3 URL:

S3 object key : <domain>/<uuid4>.<ext>           (or common/<uuid4>.<ext> for shared assets)
Stored in DB  : /cmp-media/<domain>/<uuid4>.<ext>

The AISD-115 cms-cf-media worker maps the request path /cmp-media/<key> to the S3 object <key>. The existing absolutize_media_url(path, cdn_base_url) helper prefixes the stored relative path with the site CDN host at response time, so the public API returns a fully-qualified CDN URL while the DB keeps a host-agnostic relative path. Keeping relative paths in the DB means the CDN host can change (or differ per site) without a data migration, and no presigned URL ever expires in stored data.

Columns the repopulation rewrites: content.featured_image, content.og_image, image URLs embedded in content.content_blocks (JSON), and site_settings.default_og_image / site_settings.default_favicon.