Skip to content

fix(api): allow null runtime and casting order in responses - #95

Merged
lxup merged 1 commit into
mainfrom
fix/api-nullable-response-fields
Nov 16, 2026
Merged

lxup merged 1 commit into
mainfrom
fix/api-nullable-response-fields

Conversation

@lxup

@lxup lxup commented Nov 16, 2026

Copy link
Copy Markdown
Member

Description

Loading the episodes of a TV season returned HTTP 500. The API validates every response against its DTO through parseResponseDto, and that validation rejected two fields that can legitimately hold null. A second, unrelated defect surfaced through the same error: the casting query fabricates a phantom role for actors that have no role row, which is what produced the order failures.

Changes

  • tv-episodes.dto.ts: runtime is now number | null, with nullable: true on @ApiProperty and the existing @IsNullable() decorator. 2 786 364 of 6 913 342 rows in tmdb.tv_episode (40.3 percent) have runtime IS NULL, because TMDB does not publish a duration for every episode.
  • tv-series.service.ts and movies.service.ts: the roles aggregate in getCasting is wrapped in FILTER (WHERE credit_id IS NOT NULL) and COALESCE(..., '[]'::jsonb). The left join previously emitted [{"character": null, "order": null}] for any credit without a role row. 556 910 of 3 205 162 Actor credits (17.4 percent) are in that state.
  • tv-series-credits.dto.ts and movie-credits.dto.ts: the top-level casting order is now number | null. It is computed as MIN(role.order), which has no value to report when the group is empty.
  • TvSeriesRoleDto.order and MovieRoleDto.order are deliberately left non-nullable. After the FILTER, the roles array only ever contains real roles, whose order column is NOT NULL in the database.

Impact

  • Season episode listings and movie and series casting endpoints stop returning 500. This affected effectively every season, since 40 percent of episodes lack a runtime.
  • Clients receive roles: [] instead of an array holding one fabricated role with null fields. Any consumer that rendered that entry was displaying an empty row.
  • The OpenAPI contract changes: TvEpisode.runtime, TvSeriesCasting.order and MovieCasting.order become nullable. libs/api-js/src/__generated__ needs regenerating. No frontend code reads episode.runtime or casting.order today, so no caller change is expected.
  • No database migration and no change to which rows are returned.

Test Plan

  • Open a series season whose episodes have no runtime and confirm the list loads
  • Open a season where every episode has a runtime and confirm nothing regressed
  • Open the casting of a series and of a movie, and confirm actors without a role show roles: [] rather than a null-filled entry
  • Confirm actors are still ordered correctly, including those whose order is now null
  • Regenerate the OpenAPI client and confirm the web and mobile builds pass
  • Watch the api logs and confirm no further ResponseDtoValidationError

Loading a season's episodes returned 500. parseResponseDto validates the
response against its DTO and only tolerates a null when @ApiProperty declares
nullable: true, which runtime did not — while 2 786 364 of 6 913 342 rows in
tmdb.tv_episode (40.3%) have runtime IS NULL, because TMDB does not publish a
duration for every episode. Any season holding one such episode failed.

The casting error has a different cause despite the same symptom.
tmdb.tv_series_role.order is NOT NULL, so the nulls are produced by the query
itself: getCasting left-joins credits to roles, and a credit with no role row
yields MIN(role.order) = NULL and jsonb_agg over a row of nulls, i.e. a
phantom role [{"character":null,"order":null}]. 556 910 of 3 205 162 Actor
credits (17.4%) have no role row at all.

So the two are fixed differently. runtime is genuinely nullable and gets
@isnullable. The phantom role is a bug and is removed at the source with
FILTER (WHERE credit_id IS NOT NULL) and COALESCE to '[]', which keeps
TvSeriesRoleDto.order and MovieRoleDto.order non-nullable — after the filter
the array only ever holds real roles. Only the top-level casting order
becomes nullable, since MIN over an empty group has no value to report.

Verified with tsc --noEmit on apps/api and prettier --check.
@lxup
lxup merged commit 3581d2f into main Nov 16, 2026
3 checks passed
@lxup
lxup deleted the fix/api-nullable-response-fields branch November 16, 2026 13:36
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