Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug using django ORM to update inherited history_change_reason field #1433

Open
noamk-hl opened this issue Jan 2, 2025 · 0 comments · May be fixed by #1434
Open

Bug using django ORM to update inherited history_change_reason field #1433

noamk-hl opened this issue Jan 2, 2025 · 0 comments · May be fixed by #1434

Comments

@noamk-hl
Copy link

noamk-hl commented Jan 2, 2025

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
@noamkush noamkush linked a pull request Jan 2, 2025 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant