Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix config cache for progressions starting after iteration 1

Roland Geidera78548c07e1c
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.py
index 842072ebc..ebd2c5a04 100644
--- a/wger/manager/models/slot_entry.py
+++ b/wger/manager/models/slot_entry.py
@@ -195,10 +195,10 @@ class SlotEntry(models.Model):
@property
def has_progression(self) -> bool:
"""
- Returns true if any config set has more than one entry (is a progression)
+ Returns true if the calculated config data can change across iterations
"""
return any(
- len(getattr(self, f'{field}config_set').all()) > 1
+ config.iteration != 1
for field in [
'weight',
'maxweight',
@@ -211,6 +211,7 @@ class SlotEntry(models.Model):
'sets',
'maxsets',
]
+ for config in getattr(self, f'{field}config_set').all()
)
def save(self, *args, **kwargs):
diff --git a/wger/manager/tests/test_slot_entry.py b/wger/manager/tests/test_slot_entry.py
index a0e0b2b59..109a6550a 100644
--- a/wger/manager/tests/test_slot_entry.py
+++ b/wger/manager/tests/test_slot_entry.py
@@ -730,6 +730,20 @@ class SlotEntryTestCase(WgerTestCase):
set_config.save()
self.assertIsNone(cache.get(key))
+ def test_delayed_config_not_served_from_constant_cache(self):
+ """
+ A config that only takes effect after the first iteration yields a different
+ result per iteration, so priming the cache with iteration 1 must not poison
+ the result of a later iteration
+ """
+ WeightConfig(slot_entry=self.slot_entry, iteration=3, value=100).save()
+
+ # Iteration 1, where the config is not active yet, populates the cache
+ self.assertIsNone(self.slot_entry.get_config_data(1).weight)
+
+ # Iteration 3 must reflect the config, not the cached iteration-1 result
+ self.assertEqual(self.slot_entry.get_config_data(3).weight, Decimal(100))
+
class SlotEntryDuplicateConfigTestCase(SimpleTestCase):
def test_duplicate_configs(self):