-
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
Unique database errors #451
Comments
I am not familiar with the error unfortunately. What is the |
Closing for now, but feel free to follow up if you encounter these issues again. |
Hi, Thanks, |
What version of PaperTrail are you using? |
I get a similar error. paper_trail (4.0.0.beta2) tries to save my entry while the old one still exists, when I call
|
Looks like these are issues of your database table sequence falling out of sync or something. This StackOverflow post might give you some help on how to reset the sequence on your table. Although I do find it a bit strange that it's attempting to do an 2.0.0-p247 :004 > PaperTrail::Version.find(2).reify.save!
PaperTrail::Version Load (0.2ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = ? LIMIT 1 [["id", 2]]
Widget Load (0.1ms) SELECT "widgets".* FROM "widgets" WHERE "widgets"."id" = ? LIMIT 1 [["id", 1]]
(0.0ms) SAVEPOINT active_record_1
SQL (0.0ms) UPDATE "widgets" SET "name" = ?, "updated_at" = ? WHERE "widgets"."id" = 1 [["name", "foobar"], ["updated_at", "2015-03-09 16:03:21.239462"]]
SQL (0.1ms) INSERT INTO "versions" ("created_at", "event", "item_id", "item_type", "object", "object_changes", "transaction_id") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", "2015-03-09 16:03:21.239462"], ["event", "update"], ["item_id", 1], ["item_type", "Widget"], ["object", "---\nid: 1\nname: bar\na_text: \nan_integer: \na_float: \na_decimal: \na_datetime: \na_time: \na_date: \na_boolean: \nsacrificial_column: \ntype: \ncreated_at: 2015-03-09 16:03:06.105316000 Z\nupdated_at: 2015-03-09 16:03:15.704597000 Z\n"], ["object_changes", "---\nname:\n- bar\n- foobar\nupdated_at:\n- 2015-03-09 16:03:15.704597000 Z\n- 2015-03-09 16:03:21.239462000 Z\n"], ["transaction_id", 1]]
(0.0ms) RELEASE SAVEPOINT active_record_1
=> true So perhaps it's a Postgres / ActiveRecord error. Does this happen for you w/ PaperTrail 3.x and also what version of ActiveRecord are you using? |
I get the same error with version 3.0.7 (ActiveRecord 4.2.0), but I have an idea why PaperTrail tries to Update: |
I looked more closely at the gem's code: Thereby any |
@rvfx - can you try using the |
No changes with |
Ok what is your suggested adjustment that you think would fix the issue? Drop this approach and do something more along the lines of this? inheritance_column_name = item_type.constantize.inheritance_column
class_name = attrs[inheritance_column_name].blank? ? item_type : attrs[inheritance_column_name]
klass = class_name.constantize
model = klass.unscoped.find_by_id(item_id) || klass.new Any chance you can provide a failing test case via a PR or something? |
The unscoped version works great! PR coming up... |
@rvfx - Did you ever find time to implement this code into something that could be made into a PR? I'm trying to tie of loose ends for 4.x before an official release and I think this would be a good addition, but I'm unsure of exactly what should change since I don't have test cases to duplicate this issue.. |
The code you suggested works fine. |
For what it's worth, I was seeing this issue with a custom subclass in development mode. Rails 6.0.3.6, PaperTrail 12.0.0. I had this class: class SubjectVersion < PaperTrail::Version
self.table_name = :subject_versions
end When I would reset the database with our seeds, there would be 16 records in the class SubjectVersion < ApplicationRecord
include PaperTrail::VersionConcern
end |
For what it's worth, I'm also seeing this issue in production with a custom subclass.
class PaperTrail::UuidVersion < PaperTrail::Version
self.table_name = 'uuid_versions'
end I wonder if the problem has something to do with not declaring a > PaperTrail::UuidVersion.sequence_name
=> "public.versions_id_seq"
> PaperTrail::Version.sequence_name
=> "public.versions_id_seq" However, when I check the latest values for the correct sequences > ActiveRecord::Base.connection.execute("SELECT last_value FROM versions_id_seq").to_a
=> [{"last_value"=>175167875}]
> ActiveRecord::Base.connection.execute("SELECT last_value FROM uuid_versions_id_seq").to_a
=> [{"last_value"=>50383555}] And then I check the version id of the latest version for one of our models using Uuid versions MyModel.order(:created_at).last.versions.sort_by(&:created_at).last.id
=> 50397156 it looks like it's actually using the |
Hi there -
I'm having intermittent problems that I'm having trouble replicating, but I figured I'd reach out to you guys and see if you're familiar with it.
Long story short, this is the error:
The conditions:
It's a big problem because this error ends up rolling back my update:
I re-issue the save command, and everything works fine.
Are you familiar with this condition happening? Can you give me any more insight? I'm happy to try and replicate this more and identify it, but, like I said, it seems to be an intermittent problem.
Edit: Looking at this some more, it seems to be issuing a double-insert into versions; I'm not sure why, when there's clearly only a single update to the users table.
The text was updated successfully, but these errors were encountered: