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 https://code.djangoproject.com/ticket/35246
was fixed recently, as it changed `unique` from a property to a
`cached_property`.
  • Loading branch information
ddabble committed Mar 10, 2024
1 parent 595febc commit 79d1bba
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 @@ -6,6 +6,7 @@
from functools import partial
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Sequence, Union

import django
from django.apps import apps
from django.conf import settings
from django.contrib import admin
Expand Down Expand Up @@ -817,6 +818,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 79d1bba

Please sign in to comment.