diff --git a/apps/enm/serializers.py b/apps/enm/serializers.py index 5bc9a98b..576cbddf 100644 --- a/apps/enm/serializers.py +++ b/apps/enm/serializers.py @@ -25,10 +25,20 @@ class MpointSerializer(CustomModelSerializer): read_only_fields = EXCLUDE_FIELDS + ["belong_dept", "cate"] def get_last_data(self, obj): - return cache.get(Mpoint.cache_key(obj.code), {}).get('last_data', {}) + cache_mp = cache.get(Mpoint.cache_key(obj.code)) + if isinstance(cache_mp, dict): + last_data = cache_mp.get('last_data', {}) + else: + last_data = {} + return last_data def get_gather_state(self, obj): - return cache.get(Mpoint.cache_key(obj.code), {}).get('gather_state', -2) + cache_mp = cache.get(Mpoint.cache_key(obj.code)) + if isinstance(cache_mp, dict): + gather_state = cache_mp.get('gather_state', -2) + else: + gather_state = -2 + return gather_state def validate(self, attrs): if "material" in attrs and attrs["material"]: