-
Notifications
You must be signed in to change notification settings - Fork 899
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
version_at may incorrectly return nothing #131
Comments
Thanks for flagging this. It sounds like it was quite tricky to track down. I agree with your suggested solutions, particularly the first one: I think that's most consistent. I'll try to get a fix out in the next day or two. |
Sorry about the delay in getting back to you. I hope it hasn't inconvenienced you. When PaperTrail is preparing a new I think there would be a similar difficulty with your second idea. Hmm. Have you had any further thoughts since you ran into this? |
No problem. We've worked around it so far by adding a subsecond offset in the code that relied on this. I see the update callback is |
I have a vague memory that Off the top of my head I think |
One solution for that would be to store the changes in an instance variable |
@batter Oh, good job 👍 |
Cheers, sorry this took so long to tackle! |
Had an issue where
version_at
returned nothing but should have.Turns out
version_at
usesversions.created_at
, which may be slightly later than the update that caused that version (item.updated_at
).Don't know if this is particular to Postgres. Suppose it happens more if you have higher-resolution timestamps.
Example:
In our case, we stowed away the
updated_at
of one record in another (e.g.item.campaign_updated_at
). When we later tried to use that to find the right version of the campaign, we got nothing, because it queried for versions withcreated_at > item.campaign_updated_at
. It is supposed to find the next version (representing the state the campaign was in at the given time), but instead found the version created at almost the same time as this update, representing the previous state. Sometimes there is no previous state, and we get nil.Took me a while to wrap my head around exactly why we got the nil, but it should be enough to notice that the timestamps don't match up and this can cause off-by-one-version issues with
version_at
.Would probably be best to set
versions.created_at
to the exactupdated_at
of the item, or to set another column likeversions.item_updated_at
to this value, and query for that withversion_at
.The text was updated successfully, but these errors were encountered: