Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Only re-validate a calculation when it actually changes

Roland Geider17ccc17f9906
diff --git a/wger/measurements/api/serializers.py b/wger/measurements/api/serializers.py
index 324c2369b..b51b41e77 100644
--- a/wger/measurements/api/serializers.py
+++ b/wger/measurements/api/serializers.py
@@ -180,10 +180,14 @@ class CategorySerializer(serializers.ModelSerializer):
data['dynamic_params'] = {}
return
- # A stored configuration is only re-checked when the payload moves it.
- # What it points at can be deleted afterwards, and that must not block
- # renaming or reordering the category (see _validate_value_range)
- if 'dynamic_type' not in data and 'dynamic_params' not in data:
+ # A stored configuration is only re-checked when the payload actually
+ # moves it. What it points at can be deleted afterwards, and that must
+ # not block renaming or reordering the category, also not for the
+ # clients that send the whole object back (see _validate_value_range)
+ if self.instance is not None and (dynamic_type, dynamic_params) == (
+ self.instance.dynamic_type,
+ self.instance.dynamic_params,
+ ):
return
# A typed category has a writer already, the health import or the
diff --git a/wger/measurements/tests/test_dynamic.py b/wger/measurements/tests/test_dynamic.py
index 4a4257008..dd8cef82d 100644
--- a/wger/measurements/tests/test_dynamic.py
+++ b/wger/measurements/tests/test_dynamic.py
@@ -750,6 +750,29 @@ class WhtrTestCase(DynamicMeasurementTestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
+ def test_full_object_patch_survives_a_deleted_source(self):
+ """
+ A client that sends the whole category back, configuration included,
+ can rename it as well
+ """
+ self.create_waist('90.00')
+ category = self.enable_whtr()
+ self.waist.delete()
+
+ self.user_login('test')
+ response = self.client.patch(
+ reverse('measurement-category-detail', kwargs={'pk': category.pk}),
+ {
+ 'name': 'Ratio',
+ 'unit': '',
+ 'dynamic_type': 'WHTR',
+ 'dynamic_params': category.dynamic_params,
+ },
+ content_type='application/json',
+ )
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
def test_api_requires_source(self):
"""
The category_id param is mandatory