Validate the state completion value before saving

Thanks to Manoel Brunnen (@mbru) for the report and debug
information. GitLab issue #557.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-03 18:28:25 -04:00
parent d5efd53b5b
commit 5f877cdc22
4 changed files with 42 additions and 5 deletions

View File

@@ -208,6 +208,19 @@ class WorkflowState(models.Model):
).distinct()
def save(self, *args, **kwargs):
# Solve issue #557 "Break workflows with invalid input"
# without using a migration.
# Remove blank=True, remove this, and create a migration in the next
# minor version.
try:
self.completion = int(self.completion)
except (TypeError, ValueError):
self.completion = 0
#if not self.completion:
# self.completion = 0
if self.initial:
self.workflow.states.all().update(initial=False)
return super(WorkflowState, self).save(*args, **kwargs)