Skip to content

Commit 32af3d4

Browse files
committed
Fix typing issue on previous_data (JsonField) (#2344)
* Previous data typing issue * Remove deprecate filter on queryset * Fix failed deprecated test
1 parent 697fa69 commit 32af3d4

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

local_units/serializers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ def get_location_geojson(self, unit) -> dict:
235235
return json.loads(unit.location.geojson)
236236

237237

238+
"""
239+
NOTE: This `PrivateLocalUnitDetailSerializer` is used to store the previous_data of local unit
240+
changing the serializer might effect the data of previous_data
241+
"""
242+
243+
238244
class PrivateLocalUnitDetailSerializer(NestedCreateMixin, NestedUpdateMixin):
239245
country_details = LocalUnitCountrySerializer(source="country", read_only=True)
240246
type_details = LocalUnitTypeSerializer(source="type", read_only=True)
@@ -537,24 +543,27 @@ class RejectedReasonSerialzier(serializers.Serializer):
537543

538544

539545
class LocalUnitChangeRequestSerializer(serializers.ModelSerializer):
540-
local_unit_details = PrivateLocalUnitDetailSerializer(source="local_unit", read_only=True)
541546
created_by_details = LocalUnitMiniUserSerializer(source="created_by", read_only=True)
542547
status_details = serializers.CharField(source="get_status_display", read_only=True)
543548
current_validator_details = serializers.CharField(source="get_current_validator_display", read_only=True)
549+
# NOTE: Typing issue on JsonField, So returning as string
550+
previous_data_details = serializers.SerializerMethodField(read_only=True)
544551

545552
class Meta:
546553
model = LocalUnitChangeRequest
547554
fields = (
548555
"id",
549-
"local_unit_details",
550556
"status",
551557
"status_details",
552558
"current_validator",
553559
"current_validator_details",
554560
"created_by_details",
555-
"previous_data",
561+
"previous_data_details",
556562
)
557563

564+
def get_previous_data_details(self, obj):
565+
return obj.previous_data
566+
558567

559568
class LocalUnitDeprecateSerializer(serializers.ModelSerializer):
560569
deprecated_reason = serializers.ChoiceField(choices=LocalUnit.DeprecateReason, required=True)

local_units/test_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_deprecate_local_unit(self):
8787

8888
# Test for validation
8989
response = self.client.post(url, data=data)
90-
self.assert_404(response)
90+
self.assert_400(response)
9191

9292
self.client.force_authenticate(self.root_user)
9393
# test revert deprecate
@@ -622,5 +622,5 @@ def test_latest_changes(self):
622622
# Checking the latest changes
623623
response = self.client.post(f"/api/v2/local-units/{local_unit_id}/latest-change-request/")
624624
self.assert_200(response)
625-
self.assertEqual(response.data["previous_data"]["local_branch_name"], previous_data["local_branch_name"])
626-
self.assertEqual(response.data["previous_data"]["english_branch_name"], previous_data["english_branch_name"])
625+
self.assertEqual(response.data["previous_data_details"]["local_branch_name"], previous_data["local_branch_name"])
626+
self.assertEqual(response.data["previous_data_details"]["english_branch_name"], previous_data["english_branch_name"])

local_units/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PrivateLocalUnitViewSet(viewsets.ModelViewSet):
4848
"country",
4949
"type",
5050
"level",
51-
).exclude(is_deprecated=True)
51+
)
5252
filterset_class = LocalUnitFilters
5353
search_fields = (
5454
"local_branch_name",

0 commit comments

Comments
 (0)