From ef2f05a41890b94f271f3841a821ddf0a58bccf0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 19 Mar 2026 23:40:44 +1100 Subject: [PATCH] [API] Bug fix for PartCategory cascade filter (#11562) * Bug fix for PartCategory cascade filter * Additional unit test --- src/backend/InvenTree/part/api.py | 2 +- src/backend/InvenTree/part/test_api.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/part/api.py b/src/backend/InvenTree/part/api.py index 9303c1f053..38bb79834b 100644 --- a/src/backend/InvenTree/part/api.py +++ b/src/backend/InvenTree/part/api.py @@ -161,7 +161,7 @@ class CategoryFilter(FilterSet): Note: If the "parent" filter is provided, we offload the logic to that method. """ - parent = str2bool(self.data.get('parent', None)) + parent = self.data.get('parent', None) top_level = str2bool(self.data.get('top_level', None)) # If the parent is *not* provided, update the results based on the "cascade" value diff --git a/src/backend/InvenTree/part/test_api.py b/src/backend/InvenTree/part/test_api.py index 5db1e62f49..8fc1a1bc00 100644 --- a/src/backend/InvenTree/part/test_api.py +++ b/src/backend/InvenTree/part/test_api.py @@ -111,7 +111,7 @@ class PartCategoryAPITest(InvenTreeAPITestCase): url = reverse('api-part-category-list') # star categories manually for tests as it is not possible with fixures - # because the current user is not fixured itself and throws an invalid + # because the current user is not fixtured itself and throws an invalid # foreign key constraint for pk in [3, 4]: PartCategory.objects.get(pk=pk).set_starred(self.user, True) @@ -812,9 +812,14 @@ class PartAPITest(PartAPITestBase): # Children of PartCategory<1>, do not cascade response = self.get(url, {'parent': 1, 'cascade': 'false'}) - self.assertEqual(len(response.data), 3) + # Children of PartCategory<7>, with or without cascade + # Only 1 child in either case + for cascade in ['true', 'false']: + response = self.get(url, {'parent': 7, 'cascade': cascade}) + self.assertEqual(len(response.data), 1) + def test_add_categories(self): """Check that we can add categories.""" data = {'name': 'Animals', 'description': 'All animals go here'} @@ -1644,7 +1649,7 @@ class PartCreationTests(PartAPITestBase): self.assertEqual(cat.parameter_templates.count(), 3) - # Creat a new Part, without copying category parameters + # Create a new Part, without copying category parameters data = self.post( reverse('api-part-list'), { @@ -2314,7 +2319,7 @@ class PartAPIAggregationTest(InvenTreeAPITestCase): self.assertEqual(data['allocated_to_build_orders'], 0) self.assertEqual(data['allocated_to_sales_orders'], 0) - # The unallocated stock count should equal the 'in stock' coutn + # The unallocated stock count should equal the 'in stock' count in_stock = data['in_stock'] self.assertEqual(in_stock, 126) self.assertEqual(data['unallocated_stock'], in_stock)