-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
[issue-983] querying history, convert to instance, chase foreign key on history_date #984
[issue-983] querying history, convert to instance, chase foreign key on history_date #984
Conversation
Codecov Report
@@ Coverage Diff @@
## master #984 +/- ##
=======================================
Coverage 97.64% 97.64%
=======================================
Files 23 23
Lines 1147 1147
Branches 222 222
=======================================
Hits 1120 1120
Misses 12 12
Partials 15 15
Continue to review full report at Codecov.
|
fd220ec
to
c806622
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. Good catch!
This seems not fully resolved. I had the mentioned error before version 3.2.0, now i can get a record with something like historicalOrgInstance.history.latest().instance and also historicalOrgInstance.history.latest().prev_record.instance. However getting the instance that way always returns an empty set of historical foreign key models. It only works by getting the instance through an as_of() query, then the reverse relationships models show up through the related name eg. |
More specifically here is what i am trying to do t1: org with participant 1 org = HistoricalOrg(name="original") t2: org with participant 2 org.name="modified" now what works as expected: org.as_of(before_mod).participants.all() # returns part1 what is weird when i want to work with the helpers: org.history.first().instance.name # returns "modified" as expected |
@LuxsSoft it would be best to open up a new issue and write a draft PR with the tests that show the problem. |
ok i tried to make the case |
Description
This fixes an issue whereby:
The fix:
When _history._as_of is not present use the history.history_date field instead
when chasing foreign keys.
This closes #983
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.