Skip to content

Commit 9b668d7

Browse files
committed
Fixed not resetting fields' unique attr
...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`.
1 parent d2b3e50 commit 9b668d7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

simple_history/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import warnings
55
from functools import partial
66

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

0 commit comments

Comments
 (0)