westonganger / paper_trail-association_tracking

Plugin for the PaperTrail gem to track and reify associations
MIT License
125 stars 39 forks source link

Exception on `foreign_type` field after upgrade to Rails 6 #25

Closed brightbytes-dude closed 3 years ago

brightbytes-dude commented 3 years ago

I just upgraded a Rails 5.2 app to Rails 6.0, and now see a bunch of test failures like the following:

  1) ConcernsController POST create adds parent contact to concern 
     Failure/Error: if concern.save

     ActiveModel::UnknownAttributeError:
       unknown attribute 'foreign_type' for PaperTrail::VersionAssociation.
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/composite_primary_keys-12.0.6/lib/composite_primary_keys/active_model/attribute_assignment.rb:14:in `_assign_attribute'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activemodel-6.0.3.4/lib/active_model/attribute_assignment.rb:43:in `block in _assign_attributes'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activemodel-6.0.3.4/lib/active_model/attribute_assignment.rb:42:in `each'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activemodel-6.0.3.4/lib/active_model/attribute_assignment.rb:42:in `_assign_attributes'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activerecord-6.0.3.4/lib/active_record/attribute_assignment.rb:21:in `_assign_attributes'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activemodel-6.0.3.4/lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/attr_encrypted-1.3.3/lib/attr_encrypted/adapters/active_record.rb:18:in `perform_attribute_assignment'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/attr_encrypted-1.3.3/lib/attr_encrypted/adapters/active_record.rb:25:in `assign_attributes_with_attr_encrypted'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activerecord-6.0.3.4/lib/active_record/core.rb:325:in `initialize'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activerecord-6.0.3.4/lib/active_record/inheritance.rb:70:in `new'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activerecord-6.0.3.4/lib/active_record/inheritance.rb:70:in `new'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/activerecord-6.0.3.4/lib/active_record/persistence.rb:37:in `create'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:183:in `save_bt_association'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:123:in `block in save_bt_associations'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:122:in `each'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:122:in `save_bt_associations'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:115:in `save_associations'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-association_tracking-2.1.1/lib/paper_trail_association_tracking/record_trail.rb:38:in `record_create'
     # /Users/aaron/.rvm/gems/ruby-2.5.8@early_warning/gems/paper_trail-11.1.0/lib/paper_trail/model_config.rb:46:in `block in on_create'

Here are the Gemfile.lock updates required for the Rails upgrade:

-    paper_trail (10.0.1)
+    paper_trail (11.1.0)
-    paper_trail-association_tracking (1.0.0)
+    paper_trail-association_tracking (2.1.1)

Will poke around some more, but any ideas on how to fix would save me some flailing ... :-)

westonganger commented 3 years ago

See the changelog for upgrade instructions when changing versions of PT and or PT-AT

See the below link for the resolution to this.

https://github.com/westonganger/paper_trail-association_tracking/blob/master/CHANGELOG.md#how-to-upgrade-from-v100-or-earlier

brightbytes-dude commented 3 years ago

That solved it, thanks!!

And, I can't believe that I didn't know that CHANGELOG.md is a thing - I must have wasted days of my life trying to figure out upgrade issues that were clearly documented in this file. 🤦

westonganger commented 3 years ago

Also some other projects use HISTORY.md. If you see any libraries without a changelog you should encourage them to add one.