Cannot update Ponos tasks in the Django admin because a unique constraint is always violated
- Open any Ponos task in the Django admin.
- Ensure there is at least one other task with the same run number and slug, in any other process, in the database. This is very common with
import,initialisation,thumbnailsordocker_build_dockerfiletasks on run 0. - Click Save.
-
Please correct the error below.
Constraint “unique_process_run_slug” is violated.
- Cry.
This seems to be a very obscure issue with the recent addition of support for arbitrary expressions in UniqueConstraint, and not just database fields. There are now eight ways to express the same constraint:
unique_together = (('process_id', 'run', 'slug'), )
unique_together = (('process', 'run', 'slug'), )
UniqueConstraint('process_id', 'run', 'slug', name='unique_process_run_slug') # Fails
UniqueConstraint('process', 'run', 'slug', name='unique_process_run_slug')
UniqueConstraint(F('process_id'), F('run'), F('slug'), name='unique_process_run_slug') # Fails
UniqueConstraint(F('process'), F('run'), F('slug'), name='unique_process_run_slug')
UniqueConstraint(fields=['process_id', 'run', 'slug'], name='unique_process_run_slug')
UniqueConstraint(fields=['process', 'run', 'slug'], name='unique_process_run_slug')
The two failing forms fail because they cause a very strange SQL query:
SELECT 1 AS "a"
FROM "ponos_task"
WHERE (
"ponos_task"."process_id" = ("ponos_task"."process_id")
AND "ponos_task"."run" = (0)
AND "ponos_task"."slug" = ('import')
AND NOT ("ponos_task"."id" = '5ed033c8-fa2e-4926-b673-3c73c080ff2c'::uuid)
)
LIMIT 1
The process_id = process_id instead of an actual process UUID makes no sense.
Edited by Erwan Rouchet