Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #35359 -- Made autodetector add fields referenced by GeneratedField.expression before it. #18068

Merged
merged 1 commit into from May 3, 2024

Conversation

DevilsAutumn
Copy link
Contributor

Trac ticket number

Ticket #35359

Branch description

While adding a GeneratedField field along with a new field, the AddField operations were being generated in the wrong order due to which it was breaking the migrations. The AddField operation for fields referenced by GeneratedField.expression should be added before the GeneratedField itself.

My solution modifies the _generate_added_field method in the autodetector to check if a field is a GeneratedField, then extract the referenced fields from .expression and recursively call _generate_added_field to add AddField operation for the fields referenced by .expression before GeneratedField.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • For UI changes, I have attached screenshots in both light and dark modes.

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

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

Thank you @DevilsAutumn this looks good ⭐

Can you add a release note to 5.0.5? This will be included in the upcoming release 😁

django/db/migrations/autodetector.py Outdated Show resolved Hide resolved
@DevilsAutumn DevilsAutumn force-pushed the ticket_35359 branch 2 times, most recently from 5f25b42 to d036495 Compare April 16, 2024 10:37
@sarahboyce sarahboyce force-pushed the ticket_35359 branch 4 times, most recently from 256cd68 to 41f26da Compare May 2, 2024 17:09
…s referenced by GeneratedField.expression.

Thank you to Simon Charette for the review.
Copy link
Contributor

@nessita nessita left a comment

Choose a reason for hiding this comment

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

Looks great! I pushed small edits, will merge and backport when CI is green.

@nessita nessita merged commit 9aeb38c into django:main May 3, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants