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 13, 2024
1 parent 03c1eea commit 3e6173c
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

Check warning on line 820 in simple_history/models.py

View check run for this annotation

Codecov / codecov/patch

simple_history/models.py#L820

Added line #L820 was not covered by tests
# (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 3e6173c

Please sign in to comment.