fix changeset when dummyvalues end up being used
This commit is contained in:
parent
63b2fc21a7
commit
5d6cf7e052
2 changed files with 12 additions and 5 deletions
|
@ -682,6 +682,8 @@ class ChangedObjectCollection(BaseSchema):
|
||||||
# store the dummyvalue so we can tell the user about it
|
# store the dummyvalue so we can tell the user about it
|
||||||
problems.get_object(new_operation.obj).dummy_values[field_name] = dummy_value
|
problems.get_object(new_operation.obj).dummy_values[field_name] = dummy_value
|
||||||
|
|
||||||
|
new_operation.fields[field_name] = dummy_value
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# we have set this field to a non-dummy value, if we used one before we can forget it
|
# we have set this field to a non-dummy value, if we used one before we can forget it
|
||||||
problems.get_object(new_operation.obj).dummy_values.pop(field_name, None)
|
problems.get_object(new_operation.obj).dummy_values.pop(field_name, None)
|
||||||
|
|
|
@ -252,14 +252,18 @@ class PrefetchedDatabaseOperationCollection:
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
# todo: what if unique constraint error occurs?
|
# todo: what if unique constraint error occurs?
|
||||||
|
prev = self.operations.prev.model_copy(deep=True)
|
||||||
for operation in self.operations:
|
for operation in self.operations:
|
||||||
if isinstance(operation, (CreateObjectOperation, CreateMultipleObjectsOperation)):
|
if isinstance(operation, (CreateObjectOperation, CreateMultipleObjectsOperation)):
|
||||||
self.instances.update(operation.apply_create())
|
self.instances.update(operation.apply_create())
|
||||||
|
sub_ops = operation.objects if isinstance(operation, CreateMultipleObjectsOperation) else [operation]
|
||||||
|
for sub_op in sub_ops:
|
||||||
|
prev.set(ref=sub_op.obj, values=sub_op.fields, titles=None)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
prev_obj = self.operations.prev.get(operation.obj)
|
prev_obj = prev.get(operation.obj)
|
||||||
if prev_obj is None:
|
if prev_obj is None:
|
||||||
print('WARN WARN WARN')
|
raise ValueError(f'Missing: {operation.obj}')
|
||||||
values = prev_obj.values
|
|
||||||
try:
|
try:
|
||||||
instance = self.instances[operation.obj]
|
instance = self.instances[operation.obj]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -267,5 +271,6 @@ class PrefetchedDatabaseOperationCollection:
|
||||||
instance = apps.get_model("mapdata", operation.obj.model).filter(pk=operation.obj.id).first()
|
instance = apps.get_model("mapdata", operation.obj.model).filter(pk=operation.obj.id).first()
|
||||||
else:
|
else:
|
||||||
instance = None
|
instance = None
|
||||||
if instance is not None:
|
if instance is None:
|
||||||
operation.apply(values=values, instance=instance)
|
raise ValueError('Instance to update doesn\'t exist')
|
||||||
|
operation.apply(values=prev_obj.values, instance=instance)
|
Loading…
Add table
Add a link
Reference in a new issue