django-cookie-consent icon indicating copy to clipboard operation
django-cookie-consent copied to clipboard

Add a `CookieGroup.varname` unique constraint

Open sergei-maertens opened this issue 1 year ago • 0 comments

Currently this field is not contrained as being unique, but it is being used in that way in various places where the varname is used as lookup:

  • https://github.com/jazzband/django-cookie-consent/blob/2578fc0d93f1d4a9efe756a14bbda6a0d22bcc7b/cookie_consent/urls.py#L14
  • https://github.com/jazzband/django-cookie-consent/blob/2578fc0d93f1d4a9efe756a14bbda6a0d22bcc7b/cookie_consent/urls.py#L19
  • https://github.com/jazzband/django-cookie-consent/blob/2578fc0d93f1d4a9efe756a14bbda6a0d22bcc7b/cookie_consent/util.py#L90
  • https://github.com/jazzband/django-cookie-consent/blob/2578fc0d93f1d4a9efe756a14bbda6a0d22bcc7b/cookie_consent/cache.py#L34

... and more

:boom: NOTE this has the potential of breaking existing instances if they have non-unique cookie groups in their database! As such, the change must be documented properly in the release notes.

Once this is solved, we can clean up a bit of code, see https://github.com/jazzband/django-cookie-consent/pull/100#discussion_r1333621140

Tasks

  • [ ] Add CookieGroup model unique constraint for the varname field
  • [ ] Clean up the queryset usage in all_cookie_groups implementation.
  • [ ] Document the (potential) breaking change in the changelog.

sergei-maertens avatar Sep 24 '23 13:09 sergei-maertens