-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
When using the context manager not_computed, the _resync method does not properly compute the fields update fields.
Implications:
Case 1: Model with a computed field which is not updated triggers the update of all related dependencies.
class ModelA(ComputedFieldsModel, models.Model):
field_1 = models.FloatField()
field_2 = models.FloatField()
@computed(
models.FloatField(),
depends=[['self', ['field_1', 'field_2']]])
def computed_field(self):
return func(field_1, field_2)
class ModelB(ComputedFieldsModel, models.Model):
m2m_field = models.ManyToManyField('modelA')
@computed(
models.FloatField(),
depends=[
['m2m_field', ['id']],
])
def computed_field(self):
return func(self.m2m_field)
In this case, we write modelA.save(update_fields=['field_1']) and all records of modelB are recomputed
Case 2: Update of dependent model not being triggered.
class ModelA(ComputedFieldsModel, models.Model):
field_1 = models.FloatField()
@computed(
models.FloatField(),
depends=[['self', ['field_1']]])
def computed_field(self):
return func(field_1)
class ModelB(ComputedFieldsModel, models.Model):
m2m_field = models.ManyToManyField('modelA')
@computed(
models.FloatField(),
depends=[
['m2m_field', ['field_1']],
])
def computed_field(self):
return func(self.m2m_field.field_1)
In this case, we write modelA.save(update_fields=['field_1']) and modelB is not computed
Metadata
Metadata
Assignees
Labels
No labels