Skip to content

fix(migrations): add missing migration for SpecifyUser.spprincipals#8237

Open
grantfitzsimmons wants to merge 2 commits into
mainfrom
issue-8236
Open

fix(migrations): add missing migration for SpecifyUser.spprincipals#8237
grantfitzsimmons wants to merge 2 commits into
mainfrom
issue-8236

Conversation

@grantfitzsimmons

@grantfitzsimmons grantfitzsimmons commented Jun 30, 2026

Copy link
Copy Markdown
Member

Fixes #8236

Warning

This PR affects database migrations. See migration testing instructions.

This PR introduces migration 0045_specifyuser_spprincipals_alter.py to resolve an unapplied model discrepancy warning in the logs during startup.

The discrepancy was caused by an omission in previous commits where the metadata configuration of the spprincipals field on the SpecifyUser model was changed to explicitly use related_name='specifyusers'.

Because this is a schema-metadata change on a ManyToManyField with an intermediate table (through='specify.Specifyuser_spprincipal'), Django automatically handles the reverse relationship mapping. Running this migration registers the change in django_migrations and silences the logs without altering physical database tables/columns.

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests
  • Add a reverse migration if a migration is present in the PR
  • Add migration function to
    def fix_schema_config(stdout: WriteToStdOut | None = None):

(Note: "Add migration function..." is unchecked because this is a standard, automatic Django schema metadata update rather than a custom data manipulation/key migration function).

Testing instructions

This will be easiest done by developers in a local environment:

  1. Use this branch.
  2. Start up your local development environment or run the migration command:
    python manage.py migrate specify
  3. Verify that the migration applies successfully.
  4. Run the development server:
    python manage.py runserver
  5. Confirm that the console logs no longer display the warning: "Your models in app(s): 'specify' have changes that are not yet reflected in a migration".

Rollback Verification:

Verify that the reverse migration is supported and executes cleanly:

python manage.py migrate specify 0044_alter_deletion_cascade

This should revert back to migration 0044 without errors. Run python manage.py migrate specify again to re-apply the fix.

specify@fc77f6083927:/opt/specify7$ ve/bin/python manage.py makemigrations
Migrations for 'specify':
  specifyweb/specify/migrations/0045_alter_specifyuser_spprincipals.py
    - Alter field spprincipals on specifyuser
specify@fc77f6083927:/opt/specify7$ ve/bin/python manage.py migrate
Operations to perform:
  Apply all migrations: accounts, attachment_gw, auth, businessrules, contenttypes, notifications, patches, permissions, sessions, setup_tool, specify, workbench
Running migrations:
  Applying specify.0045_alter_specifyuser_spprincipals... OK
specify@fc77f6083927:/opt/specify7$ ve/bin/python manage.py migrate
Operations to perform:
  Apply all migrations: accounts, attachment_gw, auth, businessrules, contenttypes, notifications, patches, permissions, sessions, setup_tool, specify, workbench
Running migrations:
  No migrations to apply.
specify@fc77f6083927:/opt/specify7$ ve/bin/python manage.py migrate specify 0044
Operations to perform:
  Target specific migration: 0044_alter_deletion_cascade, from specify
Running migrations:
  Rendering model states... DONE
  Unapplying specify.0045_alter_specifyuser_spprincipals... OK
specify@fc77f6083927:/opt/specify7$ exit

Summary by CodeRabbit

  • Bug Fixes
    • Updated how user-to-principal relationships are stored, improving consistency and compatibility with existing data.
    • This change is applied through a database migration and does not require any user action.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ef41550-aef8-4c9f-99d7-75181a7222ad

📥 Commits

Reviewing files that changed from the base of the PR and between 7a06d41 and 8fc6e04.

📒 Files selected for processing (1)
  • specifyweb/specify/migrations/0045_alter_specifyuser_spprincipals.py

📝 Walkthrough

Walkthrough

A new Django migration (0045_alter_specifyuser_spprincipals) is added, depending on 0044_alter_deletion_cascade. It alters the specifyuser.spprincipals field to a ManyToManyField with related_name='specifyusers' and through model specify.Specifyuser_spprincipal, resolving a detected model/migration discrepancy.

Migration 0045

Layer / File(s) Summary
AlterField migration for specifyuser.spprincipals
specifyweb/specify/migrations/0045_alter_specifyuser_spprincipals.py
Defines Migration with dependency on 0044_alter_deletion_cascade and an AlterField operation that sets spprincipals to ManyToManyField(related_name='specifyusers', through='specify.Specifyuser_spprincipal', to='specify.spprincipal').
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the added missing migration for SpecifyUser.spprincipals.
Linked Issues check ✅ Passed The migration matches issue #8236 by altering SpecifyUser.spprincipals to the expected ManyToManyField metadata.
Out of Scope Changes check ✅ Passed The PR appears scoped to the single migration needed to record the spprincipals field change.
Automatic Tests ✅ Passed Only a schema-metadata migration changed; model already matches the generated AlterField, and no test files were added—automatic tests weren't necessary.
Testing Instructions ✅ Passed Testing steps match the metadata-only M2M migration and include apply, startup warning check, and rollback verification.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8236

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

Missing migration for ⁠SpecifyUser.spprincipals field alteration

1 participant