Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniqueConstraint with InlinePanel #192

Open
minusf opened this issue Oct 14, 2024 · 3 comments
Open

UniqueConstraint with InlinePanel #192

minusf opened this issue Oct 14, 2024 · 3 comments
Labels

Comments

@minusf
Copy link

minusf commented Oct 14, 2024

Issue Summary

Converting a unique_together to UniqueConstraint results in an uncaught IntegrityError when trying to add a duplicate in a related model with InlinePanel.

    class Meta:
        # uncaught IntegrityError
        constraints = (
            models.UniqueConstraint(fields=["short_name", "meeting_site"], name="unique_room"),
        )
        # this works
        unique_together = ("short_name", "meeting_site")

I found this older issue relating to unique_together: wagtail/wagtail#2136

I also found this issue, but it seems it's only for images? wagtail/wagtail#8715

Technical details

  • Python version: Python 3.12.7
  • Django version: 5.1.2
  • Wagtail version: 6.2.2
  • Browser version: FF 131.0.2
@laymonage
Copy link
Member

laymonage commented Oct 14, 2024

This likely is an issue in django-modelcluster. The fix might be to pass include_meta_constrains=True to _get_unique_checks() in

unique_checks, date_checks = form.instance._get_unique_checks()
.

(Django ref: https://github.com/django/django/blob/97c05a64ca87253e9789ebaab4b6d20a1b2370cf/django/db/models/base.py#L1404)

If you can hack your installed django-modelcluster, could you try making the following changes in modelcluster/forms.py at line 137?

-            unique_checks, date_checks = form.instance._get_unique_checks()
+            unique_checks, date_checks = form.instance._get_unique_checks(include_meta_constraints=True)

@minusf
Copy link
Author

minusf commented Oct 14, 2024

This seems to fix it, thanks for the very quick response.

@laymonage laymonage transferred this issue from wagtail/wagtail Oct 14, 2024
@laymonage laymonage added the bug label Oct 14, 2024
@minusf
Copy link
Author

minusf commented Nov 8, 2024

Do you need me to do anything else? Will this be part of the package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants