Skip to content

[AAP-73644 ] Fix adjust_roles to use update_or_create for LOCKED_ROLES#7757

Open
jerabekjiri wants to merge 2 commits into
pulp:mainfrom
jerabekjiri:fix/adjust-roles-update-or-create
Open

[AAP-73644 ] Fix adjust_roles to use update_or_create for LOCKED_ROLES#7757
jerabekjiri wants to merge 2 commits into
pulp:mainfrom
jerabekjiri:fix/adjust-roles-update-or-create

Conversation

@jerabekjiri
Copy link
Copy Markdown
Contributor

@jerabekjiri jerabekjiri commented Jun 1, 2026

Fixes: AAP-73644

Hub pulpcore-manager migrate fails with sycopg.errors.UniqueViolation: duplicate key value violates unique constraint "core_role_name_key" when locked roles already exist in the database with locked=False. This happens because get_or_create looks up by both name and locked=True, misses the existing role, and then tries to insert a duplicate.

How to reproduce locally

  1. Start a clean Hub environment and run migrations so all roles are created normally
  2. pulpcore-manager shell_plus
  3. Set the role's locked flag to False to simulate the race condition:
role = Role.objects.get(name="ansible.ansiblerepository_creator")
role.locked = False
role.save()
  1. pulpcore-manager migrate
  2. It crashes with the UniqueViolation above because get_or_create(name=..., locked=True) doesn't find
    the existing role (it has locked=False) and tries to insert a duplicate. The crash happens in pulpcore/app/apps.py during the post_migrate signal when adjust_roles runs.

Fix

Switched to update_or_create with lookup by name only so that existing roles get corrected locked=True instead of crashing.

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

@jerabekjiri jerabekjiri force-pushed the fix/adjust-roles-update-or-create branch 3 times, most recently from 3e78c9f to c3e6e9a Compare June 1, 2026 21:16
Closes: AAP-73644

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jerabekjiri jerabekjiri force-pushed the fix/adjust-roles-update-or-create branch from c3e6e9a to 245d576 Compare June 1, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant