From 643efa448e800159aa8f24b3cf4821a58595ad08 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jun 2024 16:45:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mpointserializer=E8=8E=B7=E5=8F=96last?= =?UTF-8?q?=5Fdata=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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"]: