Unique constraint error in create_page_preview
johncarter-phntm opened this issue · comments
create_page_preview
is calling get_or_create without passing the non-unique values as defaults. This leads to a unique constraint error, eg
django.db.utils.IntegrityError: UNIQUE constraint failed: wagtail_headless_preview_pagepreview.token
if it's called twice when the signer returns the same value (eg if it's called twice in the same second).
wagtail-headless-preview/src/wagtail_headless_preview/models.py
Lines 64 to 80 in f87b2b5
One solution would be pass defaults to get_or_create, but I think maybe it'd be better to call update_page_preview regardless?
Do you have a reliable way to reproduce this? My colleague reported that he was able to trigger this error in a way that would not seem to be caused by previews being created in rapid succession. I'm asking for more details, but here is how he described it:
- Edit a page with preview panel enabled
- Browse another section of the cms
- Go back to edit the page in step 1
@Scotchester in normal use, no, but my unit test in #35 reliably hits it. I only saw one real live occurrence of it in my app logs.
I think if you generated 2 previews of the same page with different JSON in the same second you'll hit it, due to use of TimestampSigner.