Data must be copied in a particular way

This commit is contained in:
Oliver 2021-08-25 14:12:26 +10:00
parent 44ab487b62
commit dcc8acb49a

View File

@ -10,6 +10,8 @@ import os
from decimal import Decimal from decimal import Decimal
from collections import OrderedDict
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError as DjangoValidationError from django.core.exceptions import ValidationError as DjangoValidationError
@ -95,6 +97,14 @@ class InvenTreeModelSerializer(serializers.ModelSerializer):
# If instance is None, we are creating a new instance # If instance is None, we are creating a new instance
if instance is None and data is not empty: if instance is None and data is not empty:
if data is None:
data = OrderedDict()
else:
new_data = OrderedDict()
new_data.update(data)
data = new_data
# Add missing fields which have default values # Add missing fields which have default values
ModelClass = self.Meta.model ModelClass = self.Meta.model