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
This is not a usage question, this is a bug report
This bug can be reproduced with the script I provide below
This bug can be reproduced in the latest release of the paper_trail gem
This issue is about using paper_trail with rails and good migrations, so the template does not apply for this case, but i will put as much information as possible to reproduce the issue.
The bug is the following. When running a migration with good migrations the application does not autoload all the models. So a mock class needs to be created if it's necessary to use the model in the migration.
The problem is that when given a mock class in the migration, PaperTrail instead of taking class Foo it takes the class BackfillFooNames::Foo and the item_type takes the value item_type: BackfillFooNames::Foo instead of item_type: Foo. This is problematic because then the versions created by papertrail during the migrations are inconsistent with the ones in the application and cannot be used.
The problem is that in PaperTrail 14 introduced a breaking change that makes that meta attribute forbidden, so now the code above can not run in versions >= 14.0.0
As i see maybe you could rollback the forbid of has_paper_trail meta: { item_type: 'Foo' } at the own user risk and document that is risky to change that parameter as was before. Or maybe you have a better solution passing anothe parameter to the has_papertrail that could be used in the mock classes.
Im willing to open a PR to fix this issue.
The text was updated successfully, but these errors were encountered:
We are running into a similar situation where we have a weird setup with a shared module that defines logic between two ActiveRecord classes that write to the same database table and are treated as the same entity.
We want to be able to track the history as a single entity, doesn't matter which of the two classes triggered the change. This looks like:
class Shared
extend ActiveSupport::Concern
included do
self.table_name "shared_model"
has_paper_trail(
meta: {
item_type: "SharedModel"
}
)
end
end
class Foo
include Shared
end
class Bar
include Shared
end
After the upgrade to PaperTrail 14 this is now also throwing an error. And if we would remove the item_type setting it would result in the versions table having entries for Foo and Bar instead of SharedModel.
If possible we would also like to have an option to configure this somewhere.
Check the following boxes:
paper_trail
gemThis issue is about using paper_trail with rails and good migrations, so the template does not apply for this case, but i will put as much information as possible to reproduce the issue.
The bug is the following. When running a migration with good migrations the application does not autoload all the models. So a mock class needs to be created if it's necessary to use the model in the migration.
The problem is that when given a mock class in the migration, PaperTrail instead of taking class
Foo
it takes the classBackfillFooNames::Foo
and theitem_type
takes the valueitem_type: BackfillFooNames::Foo
instead ofitem_type: Foo
. This is problematic because then the versions created by papertrail during the migrations are inconsistent with the ones in the application and cannot be used.Here is the information and code to reproduce:
Migration code:
Our solution in papertrail <
14.0.0
is to also mock theitem_type
using themeta
option as shown in the following code:The problem is that in PaperTrail 14 introduced a breaking change that makes that meta attribute forbidden, so now the code above can not run in versions
>= 14.0.0
Here is more data to reproduce the problem
Papertrail version:
15.1.0
Rails version:
6.1.7.7
Gemfile:
Gemfile.lock dependencies:
As i see maybe you could rollback the forbid of
has_paper_trail meta: { item_type: 'Foo' }
at the own user risk and document that is risky to change that parameter as was before. Or maybe you have a better solution passing anothe parameter to thehas_papertrail
that could be used in the mock classes.Im willing to open a PR to fix this issue.
The text was updated successfully, but these errors were encountered: