Bug using django ORM to update inherited history_change_reason field #1433
Open
Description
Describe the bug
When using HistoricalRecords(inherit=True, history_change_reason_field=...)
, calling update(history_change_reason=...)
on the history model will update an incorrect model due to the reason field being shared between any derived model.
To Reproduce
With the models
from django.db import models
from simple_history.models import HistoricalRecords
class Base(models.Model):
history = HistoricalRecords(
inherit=True, history_change_reason_field=models.TextField()
)
class Derived1(Base):
pass
class Derived2(Base):
pass
Run the following
d1 = Derived1.history.create(history_change_reason='reason1', id=1, history_date=timezone.now())
d2 = Derived2.history.create(history_change_reason='reason2', id=1, history_date=timezone.now())
Derived1.history.update(history_change_reason='new_reason1')
d1.refresh_from_db()
d2.refresh_from_db()
print(d1.history_change_reason)
print(d2.history_change_reason)
Resulting in
reason1
new_reason1
Expected behavior
The correct historical model should be updated.
Environment (please complete the following information):
- Django Simple History Version: 3.7.0
- Django Version: 5.1.4
- Database Version: SQLite 3.47.2
Metadata
Assignees
Labels
No labels