Skip to content

Commit

Permalink
Fixed not resetting fields' unique attr
Browse files Browse the repository at this point in the history
...in Django main (5.1 alpha).
This became an issue when
django/django@e65deb7
was added, as it changed `unique` from a property to a
`cached_property`.
  • Loading branch information
ddabble committed Mar 14, 2024
1 parent d2b3e50 commit 9b668d7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import warnings
from functools import partial

import django
from django.apps import apps
from django.conf import settings
from django.contrib import admin
Expand Down Expand Up @@ -813,6 +814,13 @@ def transform_field(field):
# Unique fields can no longer be guaranteed unique,
# but they should still be indexed for faster lookups.
field.primary_key = False
# DEV: Remove this check (but keep the contents) when the minimum required
# Django version is 5.1
if django.VERSION >= (5, 1):
field.unique = False
# (Django < 5.1) Can't set `unique` as it's a property, so set the backing field
# (Django >= 5.1) Set the backing field in addition to the cached property
# above, to cover all bases
field._unique = False
field.db_index = True
field.serialize = True
Expand Down

0 comments on commit 9b668d7

Please sign in to comment.