ManageIQ / manageiq-schema

SQL schema and database migrations for ManageIQ
Apache License 2.0
20 stars 125 forks source link

Displaying notifications causes ActiveRecord::Attribute error #491

Closed kbrock closed 2 years ago

kbrock commented 4 years ago

We just upgraded rails and the ActiveRecord::Attribute model moved over to ActiveModel::Attribute.

We are storing some of these records in the database and this is causing issues.

FATAL -- : Error caught: [ArgumentError] undefined class/module ActiveRecord::Attribute::

app/models/notification.rb:101:in `text_bindings_dynamic'
app/models/notification.rb:84:in `text_bindings'
app/models/notification.rb:41:in `to_h'
app/models/notification_recipient.rb:10:in `details'

Notification#options for the field contains:

 :subject: !ruby/object:ManageIQ::Providers::Openstack::CloudManager::CloudVolume
   raw_attributes:
     ems_id: 5
     cloud_tenant_id: 2
     ems_ref: 2b0993c0-d1fe-4e08-b65d-9cbec9047cf1
     id: 102
     type: ManageIQ::Providers::Openstack::CloudManager::CloudVolume
     size: 10737418240
     availability_zone_id: 1
     cloud_volume_snapshot_id:
     name: voltwo
     status: available
     description:
     volume_type:
     bootable: false
     creation_time: '2017-11-08 02:33:11'
     iops:
     encrypted:
     href_slug:
     region_number:
     region_description:
   attributes: !ruby/object:ActiveRecord::AttributeSet
     attributes: !ruby/object:ActiveRecord::LazyAttributeHash
       delegate_hash:
         ems_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
           name: ems_id
           value_before_type_cast: 5
           type: &1 !ruby/object:ActiveModel::Type::Integer
             precision:

Our previous fix was: https://github.com/ManageIQ/manageiq-schema/pull/390

We need to create a similar schema migration to remove or fix these records

jrafanie commented 4 years ago

Interesting, so options is able to be yaml loaded but when you walk the attributes, that's when it blows up? Weird.

Never trust a ActiveRecord::LazyAttributeHash.

kbrock commented 4 years ago

I'm curious if it is a problem with CloudVolumes, or the specific error type. There are 4 cloud volume errors in the notifications table, the 4th one being that the cloud volume was removed.


Personal reference errors: 468,469,470 ok: 467

kbrock commented 4 years ago

I think the solution may be as simple as:

UPDATE notifications
SET options = REPLACE(options, 'ActiveRecord::Attribute', 'ActiveModel::Attribute')
WHERE (options LIKE '%ActiveR%');
Notification.where("options LIKE '%ActiveRecord%'") \
            .update_all("options = REPLACE(options, 'ActiveRecord::Attribute', 'ActiveModel::Attribute')"
kbrock commented 4 years ago

Interesting, so options is able to be yaml loaded but when you walk the attributes, that's when it blows up? Weird. -- @jrafanie

No, I can not access options, I got this data from sql

Never trust a ActiveRecord::LazyAttributeHash.

agreed

kbrock commented 4 years ago

Oleg came up with the conclusion that these records are not useful across versions. And we should not do heroics to keep the records alive.

kbrock commented 2 years ago

This has been deemed a low priority and the notifications can be cleared out between upgrades so a fix is present. We are a number of miq versions past this problem so I am closing.

@chessbyte please open if you feel we still may want to address in the future