Skip to content

fix(policies): preserve entityId when re-generating a policy#2382

Open
tofikwest wants to merge 1 commit intomainfrom
eng-90-fix-policy-entityid-null
Open

fix(policies): preserve entityId when re-generating a policy#2382
tofikwest wants to merge 1 commit intomainfrom
eng-90-fix-policy-entityid-null

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

Summary

  • Fixes bug where currentVersionId became null during policy regeneration
  • Root cause: deleting policy versions triggered FK cascade (SET NULL) on the policy's currentVersionId before the new version was written
  • Fix: explicitly clear currentVersionId and pendingVersionId before deleteMany within the transaction
  • Applied to both API-side and app-side (bulk regeneration) copies of updatePolicyInDatabase

Test plan

  • Regenerate a single policy — verify it saves correctly with a valid currentVersionId
  • Regenerate all policies via onboarding flow — verify none end up with null currentVersionId
  • Verify policy content displays correctly after regeneration

Resolves ENG-90

🤖 Generated with Claude Code

Resolves ENG-90

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Mar 30, 2026

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 30, 2026

PR Summary

Medium Risk
Touches policy versioning writes inside a DB transaction; incorrect ordering could impact currentVersionId/pendingVersionId integrity during regeneration, but the change is small and localized.

Overview
Prevents policy regeneration from leaving currentVersionId/pendingVersionId in an unexpected state by explicitly nulling both fields before policyVersion.deleteMany to avoid FK/cascade issues.

Applies the same ordering fix in both the API regeneration helper and the app onboarding/bulk regeneration helper so the new version can be created and then reliably re-linked as currentVersionId.

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

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

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

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Mar 30, 2026 3:29pm
comp-framework-editor Ready Ready Preview, Comment Mar 30, 2026 3:29pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
portal Skipped Skipped Mar 30, 2026 3:29pm

Request Review

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