Skip to content

fix(scan): prevent OgImage unique constraint conflict on registration (#287)#730

Open
xidik12 wants to merge 1 commit intoMerit-Systems:mainfrom
xidik12:fix/ogimage-unique-constraint
Open

fix(scan): prevent OgImage unique constraint conflict on registration (#287)#730
xidik12 wants to merge 1 commit intoMerit-Systems:mainfrom
xidik12:fix/ogimage-unique-constraint

Conversation

@xidik12
Copy link
Copy Markdown

@xidik12 xidik12 commented Mar 22, 2026

Summary

  • Fixes unique constraint violation when registering resources that share OG image URLs across different origins
  • Wraps ogImage upsert in try/catch to handle P2002 unique constraint errors
  • Falls back to create-or-update approach when the global url constraint is hit
  • Ensures multiple origins can share the same OG image URL without registration failures

Root Cause

The OgImage table had a global unique constraint on the url field (OgImage_url_key). When two origins share the same OG image URL (e.g., due to CDN or redirects), the upsert on originId_url would not find a match for the new origin, and the create branch would fail on the global url constraint.

Fix

Added error handling around the ogImage upsert that catches P2002 (unique constraint violation) and retries with a safe create-or-update pattern for the current origin.

Closes #287

…stration

When registering a new resource whose origin shares an OG image URL with
another origin, the upsert could fail with a unique constraint violation
on the url field. This adds a catch-and-retry approach that gracefully
handles the P2002 error by creating or updating the OG image entry for
the current origin.

Closes Merit-Systems#287
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 22, 2026

@xidik12 is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

error instanceof Error &&
'code' in error &&
(error as { code: string }).code === 'P2002';
if (isUniqueViolation) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OgImage upsert silently fails to update metadata when unique constraint violation occurs for an image already belonging to the same origin

Fix on Vercel

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.

Bug: Unable to register resource due to OgImage unique constraint conflict

1 participant