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

Avoid __class__ swap in pre-added field generation. #38

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions syzygy/autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,18 @@ def add_operation(self, app_label, operation, dependencies=None, beginning=False
super().add_operation(app_label, operation, dependencies, beginning)

def _generate_added_field(self, app_label, model_name, field_name):
# Delegate most of the logic to super() ...
super()._generate_added_field(app_label, model_name, field_name)
add_field = self.generated_operations[app_label][-1]
add_field.__class__ = AddField
# ... and immediately swap the added operation by an adjsuted one.
old_add_field = self.generated_operations[app_label][-1]
add_field = AddField(
old_add_field.model_name,
old_add_field.name,
old_add_field.field,
old_add_field.preserve_default,
)
add_field._auto_deps = old_add_field._auto_deps
self.generated_operations[app_label][-1] = add_field
stage = OperationStage()
self.add_operation(
self.STAGE_SPLIT,
Expand Down
Loading