Merge dev (0.53.1 Plex hotfix) into r5-data-integrity

This commit is contained in:
2026-07-26 01:39:52 +02:00
4 changed files with 26 additions and 10 deletions
+6 -1
View File
@@ -675,10 +675,15 @@ def facets(
# the result down to zero, i.e. a dead-end chip. (The already-selected genres still appear, since
# every matching title carries them, so they stay togglable.)
genre_pp = p if p.get("genre_mode") == "all" else {**p, "genres": None}
# Only rows whose `genres` is a JSON array can be unnested. A genre-less item stores JSON
# `null` (SQLAlchemy's JSONB persists a Python None as JSON null, not SQL NULL), and
# jsonb_array_elements_text() raises on a scalar ("cannot extract elements from a scalar") —
# so a single metadata-poor library (e.g. one bare Shows library with no genres) 500'd the
# whole facets endpoint. Mirror the exact guard people.py already applies to the same columns.
expanded = wsq(
db.query(func.jsonb_array_elements_text(model.genres).label("g")),
model, ids, genre_pp, kind_movie, True,
).subquery()
).filter(func.jsonb_typeof(model.genres) == "array").subquery()
for g, c in db.query(expanded.c.g, func.count()).group_by(expanded.c.g).all():
genre_counts[g] = genre_counts.get(g, 0) + c
# Content ratings — exclude its own.