fix: ensure video duration is never null when saving analysis #52
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.
This PR fixes a critical bug where video analyses were not being saved to the database if the video duration was 0 (which can happen with oEmbed fallbacks or certain video sources).
The Bug:
video_analysestable has adurationcolumn with aNOT NULLconstraint.p_duration: videoInfo?.duration || null.0 || nullevaluates tonull.nullwas passed to the database, causing the insert to fail silently (caught by a try-catch block).The Fix:
p_duration: videoInfo?.duration ?? 0.??) to only default to0ifdurationisnullorundefined.durationis0, it is preserved as0, which is a valid integer accepted by theNOT NULLconstraint.Verification:
videoInfoSchemaensuresdurationis a number (min 0).insert_video_analysis_serverfunction accepts integer input.|| nulllogic for non-nullable numeric columns.PR created automatically by Jules for task 15198584241752318780 started by @SamuelZ12
Note
Ensures database inserts never pass a null
durationfor video analyses.app/api/video-analysis/route.ts, updates RPC payload top_duration: videoInfo?.duration ?? 0when callinginsert_video_analysis_server, preserving0and avoiding null on falsy values.Written by Cursor Bugbot for commit 39f8196. This will update automatically on new commits. Configure here.