fix(migrations): migration serialization bugs for PK fields#2195
Open
seladb wants to merge 2 commits into
Open
fix(migrations): migration serialization bugs for PK fields#2195seladb wants to merge 2 commits into
seladb wants to merge 2 commits into
Conversation
- Preserve `generated=False` on PK fields in deconstruct() output - Do not skip PK fields with `source_field="id"` in CreateModel migration
Contributor
Author
|
@waketzheng @abondar I'm not sure why the coverage workflow didn't start, can you cancel and restart it (I don't have permissions to do so)? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes 2 bugs that were discovered in #2176
Motivation and Context
Two bugs in migration serialization when a PK field is configured with
non-default attributes:
generated=Falseon PK fields was lost during serialization —Field.deconstruct()only emittedgeneratedwhen the value wastruthy. If a PK field explicitly set
generated=False, the kwarg wasomitted, causing the field to revert to its per-engine default
(
Truefor IntField) on deserialization. The fix includes thegeneratedkwarg wheneverself.pkis true, preserving the explicitvalue.
source_field="<FIELD_NAME>"were dropped from CreateModel —MigrationWriter._format_create_model()collected allsource_fieldvalues and skipped any field whose
nameappeared in that set. When aPK field had
source_field="<FIELD_NAME>", its own name matched the set entryand it was incorrectly excluded from the migration output. The fix
exempts PK fields from this deduplication logic.
How Has This Been Tested?
generatedin PK and non-PK fieldssource_fieldthat is similar to the field nameChecklist: