-
Notifications
You must be signed in to change notification settings - Fork 902
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.next returns same version #317
Comments
Can you provide some more information please? (PaperTrail version / ActiveRecord version, etc.) What type of database are you using? This could be related to #314 if you are seeing this in testing? |
Ruby 2.0.0p247 I did read over #314, however the issue is not manifesting in testing, but in development. |
Can you print the return results from this in the console please? > version
> version.sibling_versions
> version.sibling_versions.subsequent(version)
> version.sibling_versions.map { |v| p [v.id, v.send(PaperTrail.timestamp_field)] }
# this reloads the association
> version.sibling_versions(true)
> version.sibling_versions.subsequent(version)
> version.sibling_versions.map { |v| p [v.id, v.send(PaperTrail.timestamp_field)] } |
I can provide a yaml formatted dump, if needed, but it's quite long. version => #<PaperTrail::Version id: 985, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:27:48", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc..."> version.sibling_versions => #<ActiveRecord::Relation [#<PaperTrail::Version id: 956, item_type: "Project", item_id: 202, event: "create", whodunnit: "4", object: nil, created_at: "2014-01-08 21:38:31", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 957, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Title\ncomment: Add a comment\n...", created_at: "2014-01-08 21:39:18", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 961, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:28:36", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 962, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:30:24", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 963, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:30:30", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 964, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:35:19", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 965, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:35:23", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 966, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:36:19", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 975, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-10 21:07:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 980, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-10 22:17:51", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, ...]> version.sibling_versions.subsequent(version) PaperTrail::Version Load (0.3ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at > '2014-01-13 19:27:48.000000') ORDER BY created_at ASC
=> #<ActiveRecord::Relation [#<PaperTrail::Version id: 985, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:27:48", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 986, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:29:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 987, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: '...", created_at: "2014-01-13 21:34:46", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 988, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: '...", created_at: "2014-01-13 21:35:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">]> version.sibling_versions.map { |v| p [v.id, v.send(PaperTrail.timestamp_field)] } [956, Wed, 08 Jan 2014 21:38:31 UTC +00:00]
[957, Wed, 08 Jan 2014 21:39:18 UTC +00:00]
[961, Wed, 08 Jan 2014 22:28:36 UTC +00:00]
[962, Wed, 08 Jan 2014 22:30:24 UTC +00:00]
[963, Wed, 08 Jan 2014 22:30:30 UTC +00:00]
[964, Wed, 08 Jan 2014 22:35:19 UTC +00:00]
[965, Wed, 08 Jan 2014 22:35:23 UTC +00:00]
[966, Wed, 08 Jan 2014 22:36:19 UTC +00:00]
[975, Fri, 10 Jan 2014 21:07:00 UTC +00:00]
[980, Fri, 10 Jan 2014 22:17:51 UTC +00:00]
[981, Fri, 10 Jan 2014 22:21:04 UTC +00:00]
[984, Mon, 13 Jan 2014 19:25:44 UTC +00:00]
[985, Mon, 13 Jan 2014 19:27:48 UTC +00:00]
[986, Mon, 13 Jan 2014 19:29:00 UTC +00:00]
[987, Mon, 13 Jan 2014 21:34:46 UTC +00:00]
[988, Mon, 13 Jan 2014 21:35:00 UTC +00:00] version.sibling_versions(true) PaperTrail::Version Load (0.4ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202
=> #<ActiveRecord::Relation [#<PaperTrail::Version id: 956, item_type: "Project", item_id: 202, event: "create", whodunnit: "4", object: nil, created_at: "2014-01-08 21:38:31", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 957, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Title\ncomment: Add a comment\n...", created_at: "2014-01-08 21:39:18", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 961, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:28:36", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 962, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:30:24", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 963, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:30:30", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 964, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:35:19", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 965, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:35:23", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 966, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-08 22:36:19", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 975, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-10 21:07:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 980, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: A...", created_at: "2014-01-10 22:17:51", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, ...]> version.sibling_versions.subsequent(version) PaperTrail::Version Load (0.4ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at > '2014-01-13 19:27:48.000000') ORDER BY created_at ASC
=> #<ActiveRecord::Relation [#<PaperTrail::Version id: 985, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:27:48", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 986, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:29:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 987, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: '...", created_at: "2014-01-13 21:34:46", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">, #<PaperTrail::Version id: 988, item_type: "Project", item_id: 202, event: "update", whodunnit: "4", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: '...", created_at: "2014-01-13 21:35:00", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">]> version.sibling_versions.map { |v| p [v.id, v.send(PaperTrail.timestamp_field)] } [956, Wed, 08 Jan 2014 21:38:31 UTC +00:00]
[957, Wed, 08 Jan 2014 21:39:18 UTC +00:00]
[961, Wed, 08 Jan 2014 22:28:36 UTC +00:00]
[962, Wed, 08 Jan 2014 22:30:24 UTC +00:00]
[963, Wed, 08 Jan 2014 22:30:30 UTC +00:00]
[964, Wed, 08 Jan 2014 22:35:19 UTC +00:00]
[965, Wed, 08 Jan 2014 22:35:23 UTC +00:00]
[966, Wed, 08 Jan 2014 22:36:19 UTC +00:00]
[975, Fri, 10 Jan 2014 21:07:00 UTC +00:00]
[980, Fri, 10 Jan 2014 22:17:51 UTC +00:00]
[981, Fri, 10 Jan 2014 22:21:04 UTC +00:00]
[984, Mon, 13 Jan 2014 19:25:44 UTC +00:00]
[985, Mon, 13 Jan 2014 19:27:48 UTC +00:00]
[986, Mon, 13 Jan 2014 19:29:00 UTC +00:00]
[987, Mon, 13 Jan 2014 21:34:46 UTC +00:00]
[988, Mon, 13 Jan 2014 21:35:00 UTC +00:00] |
Thanks for the report, looks like the timestamps are definitely not the issue. Is there an easy way you can print out the SQL that is reported from the original syntax in your issue report? # Each of these should print out SQL in the console the first time you access the `index` for it
version = PaperTrail::Version.find(985)
version.index # returns 12
version.previous.index # returns 11
version.next.index # returns 12, NOT 13 as expected |
version = PaperTrail::Version.find(985) PaperTrail::Version Load (0.2ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = ? LIMIT 1 [["id", 985]] version.index PaperTrail::Version Load (0.2ms) SELECT created_at, id FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 ORDER BY created_at ASC
=> 12 version.previous.index PaperTrail::Version Load (0.3ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at < '2014-01-13 19:27:48.000000') ORDER BY created_at DESC LIMIT 1
PaperTrail::Version Load (0.1ms) SELECT created_at, id FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 ORDER BY created_at ASC
=> 11 version.next.index PaperTrail::Version Load (0.3ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at > '2014-01-13 19:27:48.000000') ORDER BY created_at ASC LIMIT 1
PaperTrail::Version Load (0.2ms) SELECT created_at, id FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 ORDER BY created_at ASC
=> 12 |
That being said, it looks like it may be an issue of Timestamp. Let's look at the SQL being executed for PaperTrail::Version Load (0.4ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at > '2014-01-13 19:27:48.000000') ORDER BY created_at ASC So it is looking for the first entry in the |
I did a short test in the production environment which is running Postgres on Heroku and |
I'm looking at rails/rails#10855 and wondering if that could be related. What happens if you print out: > version = PaperTrail::Version.find(985)
> version.created_at.usec
> version.created_at.nsec
> version.created_at_before_type_cast |
PaperTrail::Version Load (0.2ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = ? LIMIT 1 [["id", 985]]
=> #<PaperTrail::Version id: 985, item_type: "Project", item_id: 202, event: "update", whodunnit: "18", object: "---\nid: 202\nname: Add Char/Number limits\ncomment: I...", created_at: "2014-01-13 19:27:48", object_changes: "--- !ruby/hash:ActiveSupport::HashWithIndifferentAc...">
"2014-01-13 19:27:48.150878" |
Whoops, sorry corrected my comment above. But anyways that seems to explain what the issue is. The microseconds / milliseconds not being passed into the query for some reason. |
Does it seem odd that for version 985 > version.next
PaperTrail::Version Load (0.3ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at > '2014-01-13 19:27:48.000000') ORDER BY created_at ASC LIMIT 1
=> #<PaperTrail::Version id: 985... > version.previous
PaperTrail::Version Load (0.3ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_type" = 'Project' AND "versions"."item_id" = 202 AND (created_at < '2014-01-13 19:27:48.000000') ORDER BY created_at DESC LIMIT 1
=> #<PaperTrail::Version id: 984... |
No. Because When you invoke |
Ok kept digging into this and found rails/rails#12422 which seems similar. I have to think this is a third party issue of sorts because I can't reproduce it, and if it was a problem with the PaperTrail code I'm pretty sure our automated test suite would have caught it. |
Hmm, that does appear to be the issue I'm having. I don't want to upgrade my current application to 4.0.2 at the moment, but I'm creating a barebones app and model with has_paper_trail to see if the Ruby version is indeed the issue. |
…rn if primary key is an integer. This makes some of the changes to these scope methods that came from 6a4aba2 more flexible, in that the user can choose to compare timestamps if desired, but it defaults to comparing and sorting, via the primary key (if it is an integer). If the primary key is not an integer, it still defaults to using the PaperTrail.timestamp_field. This is my proposed fix for #314, and I also believe it should fix #317. It seems that that this issue is usually encountered when testing PaperTrail with MySQL (presumably due to lack of microsecond timestamp support).
If I have a widget with 15 versions, and I have version 12, I run the following:
The same behavior happens with
widget.next_version
as well.The text was updated successfully, but these errors were encountered: