You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A clear and concise description of what the bug is.
In 3.1 HistoricForeignKey was introduced which is intended to work with Model.history.as_of(timepoint) and this works.
In 3.1.1, calling .instance on a historic record lookup does not populate _as_of which is necessary for HistoricForeignKey to work. You can query history with as_of(timepoint) and things work properly, but querying Model.history directly then converting to an instance cannot chase the foreign keys properly.
My workaround in another project:
if isinstance(value, Value.history.model):
# work around https://github.com/jazzband/django-simple-history/issues/983
# queries beginning with as_of properly inject, but direct selections
# converted to instances do not... :| I missed something!!
setattr(value, "_as_of", value.modified_at)
# then value.instance properly works
The text was updated successfully, but these errors were encountered:
In the end, if you did not query history with as_of, and you end up with a historical instance, if you call .instance on it, the HistoricalForeignKey chasers will use a fallback of the history_date of the record that made the instance when chasing relations! This was an easy fix and an easy win, and makes django-simple-history more powerful.
Describe the bug
A clear and concise description of what the bug is.
In 3.1 HistoricForeignKey was introduced which is intended to work with Model.history.as_of(timepoint) and this works.
In 3.1.1, calling
.instance
on a historic record lookup does not populate_as_of
which is necessary for HistoricForeignKey to work. You can query history with as_of(timepoint) and things work properly, but querying Model.history directly then converting to an instance cannot chase the foreign keys properly.My workaround in another project:
The text was updated successfully, but these errors were encountered: