-
Notifications
You must be signed in to change notification settings - Fork 901
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
Redefinition of PaperTrail::Version stopped working in v12 #1305
Comments
For some reason, the default class from the gem is never overridden by our code in v12: v11.1.0
v12.0.0
|
Hey @toncid, thanks for sharing your experience. I'm just chiming in that I'm fighting the same issue... without much success. I tried a few things but couldn't make it work. I reverted back to to Edit: |
@StanBright Thanks for the follow-up and testing in the production mode. We have tried a few different approaches to circumvent the problem, none of them successful, so reverting to v11.1 was also the only option left. |
I can confirm the issue, also i have no resolution. On our projects we go with a lower version of papertrail for now. |
Thank you for opening this and for everyone providing all of the extra details. Can confirm this issue. We recently changed loading in #1281 |
It seems like it could potentially work if we move the overridden |
Hi y'all. Thanks for the report. I tried to reproduce this in a new rails app (6.1) but no luck.
What am I missing? |
We can reproduce in Rails 6.1 by enabling classic mode |
Thanks Todd. With that setting, I can reproduce the issue:
Classic mode is deprecated, but I'd like PT to support it as long as is practical. Contributions are welcome. If there are practical workarounds, let's document them. In the changelog, I will reclassify #1281 as a breaking change. |
Hi @toncid, @StanBright, @criess, does it work if you move the overridden |
You might also want to play around with adding a |
This is happening because the new railtie is requiring the active_record framework: https://github.com/paper-trail-gem/paper_trail/pull/1281/files#diff-f226b8d714b180354bcadd32e8b0f55afb2e4d9e2c639c28bcf248aba53b38e0R26 , and the previous engine didn't. The AR framework in turn requires the model class. Apparently using AR-only PT never supported overriding the Version class. (possibly because it doesn't make much sense. Who is doing the autoloading if not rails?) I have worked around this by adding this in my PT initializer: module PaperTrail
remove_const :Version
end I believe the proper fix is to not require the Version model, but to keep adding the autoload path. Here is a StackOverflow answer suggesting how to do it: https://stackoverflow.com/a/6394946 . So maybe something like moving the |
Thanks everyone for a productive discussion.
I'll close this for now with the understanding that our preferred solution is zeitwerk. - config.autoloader = :classic # deprecated
+ config.autoloader = :zeitwerk PRs welcome. |
Sorry for not mentioning this. I'm seeing the error with the zeitwerk loader. |
Hmmmm, we're using zeitwerk and ran into this issue. However, we've solved it by creating a new class with our additions ( |
I like the sound of that, Joel. You might also try
I haven't tested the above, and I don't use Custom Version Classes personally, so I'd warmly welcome documentation PRs from people who do. |
Well, I spoke too soon. That change worked just fine in rails console but completely blew up our spec suite (specs won't event run because of an error during setup). I'll report back after I know more. |
@jaredbeck your |
Hey guys, why is this issue closed? I am still experimenting the same and I couldn't make any of the workarounds work. Maybe I am doing something wrong, that is our custom module which is getting ignored when upgrading from module PaperTrail
class Version < ActiveRecord::Base
include PaperTrail::VersionConcern
belongs_to :user, foreign_key: :whodunnit, optional: true
end
end |
@istvan-ujjmeszaros I was able to work around this bug by defining Works like a charm! # frozen_string_literal: true
class Version < PaperTrail::Version
belongs_to :item, polymorphic: true
belongs_to :user
end |
Switched to 6.1.7 with zeitwerk. Facing the same issue with paper_trail 13.0.0 and with 14.0.0 We define
in and this never gets loaded because of
What I had to do for the spec to pass is to do
And I don't believe this should be used, especially with zeitwerk. Right? |
March 2023: I can report this issue to be current still running Rails 6.1 with Zeitwerk and PT 14.
|
@weezing Inheritance only works if you work from the item and up, but is useless if your starting point is Contract.new.versions # works
# versus
PaperTrail::Version.includes(:item).where(item_type: 'Contract').order(created_at: :desc) # does not work |
I have tried @thebravoman solution and it works. Create an initializer that requires our custom model. |
Hello,
It seems that the v12 somehow interferes with Rails lazy autoloading in the development environment. The overriding class is no longer concerned. See below the script for more info.
Check the following boxes:
paper_trail
gemDue to limited volunteers, we cannot answer usage questions. Please ask such
questions on StackOverflow.
Bug reports must use the following template:
The script runs well, but this is due to avoided autoloading (
PaperTrail::Version
is defined in the same script).The problem is with Rails when
PaperTrail::Version
is redefined in another file (see: https://github.com/paper-trail-gem/paper_trail/blob/v12.0.0/README.md#5b2-item-association). This no longer works in development where autoloading is lazy.Any advice?
The text was updated successfully, but these errors were encountered: