Skip to content

Commit

Permalink
Avoid __class__ swap in pre-added field generation.
Browse files Browse the repository at this point in the history
While clever it makes it harder to reason about the intended effect.
  • Loading branch information
charettes committed Nov 5, 2023
1 parent a36026a commit 93fcbb6
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 93fcbb6

Please sign in to comment.