Repository navigation
fix(api): allow null runtime and casting order in responses - #95
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 holdnull. 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 theorderfailures.Changes
tv-episodes.dto.ts:runtimeis nownumber | null, withnullable: trueon@ApiPropertyand the existing@IsNullable()decorator. 2 786 364 of 6 913 342 rows intmdb.tv_episode(40.3 percent) haveruntime IS NULL, because TMDB does not publish a duration for every episode.tv-series.service.tsandmovies.service.ts: therolesaggregate ingetCastingis wrapped inFILTER (WHERE credit_id IS NOT NULL)andCOALESCE(..., '[]'::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.tsandmovie-credits.dto.ts: the top-level castingorderis nownumber | null. It is computed asMIN(role.order), which has no value to report when the group is empty.TvSeriesRoleDto.orderandMovieRoleDto.orderare deliberately left non-nullable. After theFILTER, the roles array only ever contains real roles, whoseordercolumn isNOT NULLin the database.Impact
roles: []instead of an array holding one fabricated role with null fields. Any consumer that rendered that entry was displaying an empty row.TvEpisode.runtime,TvSeriesCasting.orderandMovieCasting.orderbecome nullable.libs/api-js/src/__generated__needs regenerating. No frontend code readsepisode.runtimeorcasting.ordertoday, so no caller change is expected.Test Plan
roles: []rather than a null-filled entryorderis now nullResponseDtoValidationError