workflows: set bo fields to empty value only if value before compute is empty (#45135)
gitea-wip/wcs/pipeline/head Build started... Details
gitea/wcs/pipeline/head Build started... Details

This commit is contained in:
Thomas NOËL 2020-07-15 17:30:15 +02:00 committed by Thomas NOEL
parent 8dfa5c8c62
commit 1861bb36f6
2 changed files with 19 additions and 10 deletions

View File

@ -3784,6 +3784,16 @@ def test_set_backoffice_field(http_requests, two_pubs):
formdata = formdef.data_class().get(formdata.id)
assert formdata.data['bo1'] is None
# check a value computed as the empty string is stored as an empty string, not None
item.fields = [{'field_id': 'bo1', 'value': '=""'}]
item.perform(formdata)
formdata = formdef.data_class().get(formdata.id)
assert formdata.data['bo1'] == ''
item.fields = [{'field_id': 'bo1', 'value': '{{ does_not_exist }}'}]
item.perform(formdata)
formdata = formdef.data_class().get(formdata.id)
assert formdata.data['bo1'] == ''
assert LoggedError.count() == 0
item.fields = [{'field_id': 'bo1', 'value': '= ~ invalid python ~'}]
@ -4233,7 +4243,7 @@ def test_set_backoffice_field_date(two_pubs):
# invalid values => do nothing
assert LoggedError.count() == 0
for value in ('plop', {}, []):
for value in ('plop', '={}', '=[]'):
item = SetBackofficeFieldsWorkflowStatusItem()
item.parent = st1
item.fields = [{'field_id': 'bo1', 'value': value}]

View File

@ -107,16 +107,15 @@ class SetBackofficeFieldsWorkflowStatusItem(WorkflowStatusItem):
except IndexError:
continue
try:
new_value = self.compute(field['value'], raises=True,
formdata=formdata, status_item=self)
except:
continue
if new_value == '':
# assign empty strings as None, as that will work for all field
# types
if not field.get('value'):
# assign empty value as None, as that will work for all field types
new_value = None
else:
try:
new_value = self.compute(field['value'], raises=True,
formdata=formdata, status_item=self)
except:
continue
if formdef_field.convert_value_from_anything:
try: