-
Notifications
You must be signed in to change notification settings - Fork 336
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
Error: Tried to load unspecified class Psych::DisallowedClass of a model #388
Comments
This error seems to be coming from here:
https://github.com/public-activity/public_activity/blob/f6873889d5606314b2141fd49b42ea74c0a2e3dc/lib/public_activity/orm/active_record/activity.rb#L36-L46
but if you are truly still using Rails 6, then it doesn't make any sense that you are getting an error from Psych. If I am reading the condition on line 40 correctly, you should still be using the older serialize mechanism, which doesn't directly involve YAML (and thus Psych).
How has the rest of your upgrade gone?
I note in one of my Rails 7 apps I have set the gem psych to `< 4`, perhaps for this reason. Not sure if that's a very good idea, going to have to reckon with that as I upgrade to 7.1.
Walter
… On May 29, 2024, at 5:18 AM, Himalaya Pal ***@***.***> wrote:
Note: Quote is my model name.
After upgrading from Rails 5 to Rails 6 and from Ruby 2.3 to Ruby 3, I encountered an error. The error message indicates an issue with loading an unspecified class Quote. Below are the details of the error and the relevant part of the code:
pry(#<#<Class:0x000061b9016dd758>>)> activity.parameters
Psych::DisallowedClass: Tried to load unspecified class: Quote
from /home/cosine/.rbenv/versions/3.0.2/lib/ruby/3.0.0/psych/class_loader.rb:99:in `find'
[2] pry(#<#<Class:0x000061b9016dd758>>)> activity
=> #<PublicActivity::Activity:0x000061b901421898
id: 272678,
trackable_type: "Quote",
trackable_id: 28253,
owner_type: "User",
owner_id: 48,
key: "activity.quote.project_details_updated",
parameters: #<PublicActivity::Activity:0x12fd4>
[3] pry(#<#<Class:0x000061b9016dd758>>)>
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
@quote = Quote.find(self.id)
@quote.create_activity(
key: 'activity.quote.project_details_updated',
params: {
user_role: @current_user.roles.pluck(:name),
project_details: self.changed_attributes,
current_project_details: @quote
},
owner: @current_user
) As you can see, in the activity creation part, I am sending the actual ActiveRecord I am trying to fix this issue by converting it to a hash. In my case, I am using @quote = Quote.find(self.id)
quote_struct = OpenStruct.new(@quote.attributes)
@quote.create_activity(
key: 'activity.quote.project_details_updated',
params: {
user_role: @current_user.roles.pluck(:name),
project_details: self.changed_attributes,
current_project_details: quote_struct
},
owner: @current_user
) I don't think this is the proper solution as it requires changing every old data entry. Also i am not using psych gem. Other than this, the version upgrade is going well with some minor syntax changes. |
What you may want to do then is configure Psych to recognize all of the models in your app. You can do that in the application.rb, and there may already be a placeholder comment there, depending on the way you ran your upgrade, to guide you. But googling that error message should give you the particular syntax. I think there may even be some way to extend that list programmatically, perhaps using ApplicationRecord.descendants, so you don't have to remember to maintain it.
Walter
… On May 29, 2024, at 8:11 AM, Himalaya Pal ***@***.***> wrote:
@quote = Quote.find(self.id)
@quote.create_activity(
key: 'activity.quote.project_details_updated',
params: {
user_role: @current_user.roles.pluck(:name),
project_details: self.changed_attributes,
current_project_details: @quote
},
owner: @current_user
)
As you can see, in the activity creation part, I am sending the actual ActiveRecord @quote in current_project_details.
I am trying to fix this issue by converting it to a hash. In my case, I am using OpenStruct like this:
@quote = Quote.find(self.id)
quote_struct = ***@***.***)
@quote.create_activity(
key: 'activity.quote.project_details_updated',
params: {
user_role: @current_user.roles.pluck(:name),
project_details: self.changed_attributes,
current_project_details: quote_struct
},
owner: @current_user
)
I don't think this is the proper solution as it requires changing every old data entry.
Other than this, the version upgrade is going well with some minor syntax changes.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
I will look into it. |
Seems like you are serializing whole Active Record objects which I would definitely NOT do. A bypass for this is allowing this class to be serialized, but why do you need an actual instance of the record and not just its id? |
I am currently upgrading old code written by other developers in Ruby 2 and Rails 5 to Ruby 3 and Rails 6. As part of this upgrade, I have encountered legacy code that relies on serializing entire Active Record objects. While it would be ideal to only serialize the IDs and fetch the records as needed, this approach doesn't fit seamlessly with the existing codebase. I did attempt to bypass the issue by allowing the class to be serialized, but this led to improper serialization and subsequent data issues. As a workaround, I am manipulating the old data to fit the current code by converting it into OpenStruct. |
Note: Quote is my model name.
After upgrading from Rails 5 to Rails 6 and from Ruby 2.3 to Ruby 3, I encountered an error. The error message indicates an issue with loading an unspecified class Quote. Below are the details of the error and the relevant part of the code:
The text was updated successfully, but these errors were encountered: