Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

@google-labs-jules google-labs-jules bot commented Jan 13, 2026

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:

  • The video_analyses table has a duration column with a NOT NULL constraint.
  • The API logic used p_duration: videoInfo?.duration || null.
  • In JavaScript, 0 || null evaluates to null.
  • When a video had a duration of 0, null was passed to the database, causing the insert to fail silently (caught by a try-catch block).
  • The user who generated the analysis saw the results (returned from API response), but the data was never persisted.
  • Sharing the link resulted in a 404 error for other users because the record didn't exist.

The Fix:

  • Changed the assignment to p_duration: videoInfo?.duration ?? 0.
  • This uses the nullish coalescing operator (??) to only default to 0 if duration is null or undefined.
  • If duration is 0, it is preserved as 0, which is a valid integer accepted by the NOT NULL constraint.

Verification:

  • Verified via code review that videoInfoSchema ensures duration is a number (min 0).
  • Verified insert_video_analysis_server function accepts integer input.
  • Verified that no other fields had similar risky || null logic for non-nullable numeric columns.

PR created automatically by Jules for task 15198584241752318780 started by @SamuelZ12


Note

Ensures database inserts never pass a null duration for video analyses.

  • In app/api/video-analysis/route.ts, updates RPC payload to p_duration: videoInfo?.duration ?? 0 when calling insert_video_analysis_server, preserving 0 and avoiding null on falsy values.
  • No other behavior changes.

Written by Cursor Bugbot for commit 39f8196. This will update automatically on new commits. Configure here.

Fixes a bug where video analysis failed to save to the database when the video duration was 0 (e.g., from oEmbed fallback), causing 404 errors on shared links.
The issue was caused by `videoInfo?.duration || null` evaluating to `null` when duration was `0`, violating the `NOT NULL` constraint on the `duration` column.
Changed logic to `videoInfo?.duration ?? 0` to preserve `0` as a valid integer value.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link

vercel bot commented Jan 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
tldw Ready Ready Preview, Comment Jan 13, 2026 5:44pm

@SamuelZ12 SamuelZ12 temporarily deployed to fix-video-analysis-save-duration-null-check-15198584241752318780 - longcut PR #52 January 13, 2026 17:43 — with Render Destroyed
@supabase
Copy link

supabase bot commented Jan 13, 2026

This pull request has been ignored for the connected project ioczjdqhdcjmrnsicqqz because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@SamuelZ12 SamuelZ12 marked this pull request as ready for review January 14, 2026 16:09
Copilot AI review requested due to automatic review settings January 14, 2026 16:09
@SamuelZ12 SamuelZ12 merged commit 0faa725 into main Jan 14, 2026
6 of 7 checks passed
@SamuelZ12 SamuelZ12 deleted the fix-video-analysis-save-duration-null-check-15198584241752318780 branch January 14, 2026 16:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug where video analyses with a duration of 0 were failing to save to the database due to incorrect null handling logic. The issue occurred because the logical OR operator (||) treated 0 as falsy, converting it to null and violating the NOT NULL constraint on the duration column.

Changes:

  • Replaced || with ?? operator for duration assignment to properly handle 0 values
  • Ensured 0 duration videos can be persisted while maintaining database NOT NULL constraint

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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