fix: 账号导入500 (#10255)

Co-authored-by: feng <1304903146@qq.com>
pull/10257/head
fit2bot 2023-04-19 10:57:38 +08:00 committed by GitHub
parent 3bc8eda66a
commit fc4a77df1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -75,6 +75,9 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
initial_data['name'] = name
def from_template_if_need(self, initial_data):
if isinstance(initial_data, str):
return
template_id = initial_data.pop('template', None)
if not template_id:
return

View File

@ -70,9 +70,13 @@ class AssetPlatformSerializer(serializers.ModelSerializer):
class AssetAccountSerializer(AccountSerializer):
add_org_fields = False
asset = serializers.PrimaryKeyRelatedField(queryset=Asset.objects, required=False, write_only=True)
clone_id: str
clone_id = None
def to_internal_value(self, data):
# 导入时data有时为str
if isinstance(data, str):
return super().to_internal_value(data)
clone_id = data.pop('id', None)
ret = super().to_internal_value(data)
self.clone_id = clone_id