annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Annotate no longer works with Rails 5.2 models

Open kieraneglin opened this issue 8 years ago • 11 comments

On Rails 5.1, annotate worked as expected. After updating to 5.2, I noticed that annotate was not working as part of my post-update functionality testing.

I have no frozen string literal comments in my models.

Sample output:

Warning: exception can't modify frozen String raised while trying to load model class app/models/user.rb
Unable to annotate app/models/game.rb: can't modify frozen String
Unable to annotate app/models/game.rb: no implicit conversion of nil into Array
Unable to annotate app/models/user.rb: can't modify frozen String
Unable to annotate app/models/user.rb: no implicit conversion of nil into Array
Model files unchanged.

I'm unsure if this affects anything except models, since that's the only functionality I'm using.

Versions Rails: 5.2.0.beta2 Ruby: 2.4.2 Annotate: 2.7.2

kieraneglin avatar Dec 21 '17 20:12 kieraneglin

Have you tried it the dev version of annotate gem (see README for instructions)?

ctran avatar Dec 22 '17 03:12 ctran

Sorry for the delay! I've been busy with holidays and all.

Updating to the dev version mostly works. However, using ActiveStorage's has_one_attached (see here) trips it up with the following error:

Warning: exception can't modify frozen String raised while trying to load model class app/models/user.rb
Model files unchanged.

It seems to still annotate the model (and all other models work fine), but the error is still raised.

Let me know if you need any more information!

kieraneglin avatar Dec 27 '17 21:12 kieraneglin

@ctran I have same problem on Rails 5.2.0.beta2 and the dev version of annotate gem.

Error messages:

Unable to annotate app/models/author.rb: can't modify frozen String
Unable to annotate app/models/author.rb: no implicit conversion of nil into Array

I have three models (Category, Post and Author). The former two models get annotated correctly, but the last one (Author) can not be annotated.

kuroda avatar Jan 07 '18 11:01 kuroda

@ctran I noticed an interesting phenomenon.

Annotation goes well on the tables that have foreign key constraints.

In order to confirm my theory, I added a column with foreign key constraint to the authors table. Then, the Author model gets annotated correctly.

kuroda avatar Jan 07 '18 11:01 kuroda

I have same issue with following versions.

ruby 2.5.0
rails 5.2.0.beta2
annotate 2.7.2

fshin1988 avatar Jan 13 '18 07:01 fshin1988

Same here, with same versions as @fshin1988 except rails 5.2.0.rc1

damienlethiec avatar Feb 08 '18 11:02 damienlethiec

@kuroda, same here Model without index (belongs_to association) on any other column may be causing this issue.

Setting 'show_indexes' => 'false', annotated the model.

ammit avatar Feb 18 '18 13:02 ammit

Also on Ruby 2.5, Rails 2.5.0.beta2 and annotate 2.7.2.

Setting 'show_indexes' => 'false', annotated the model. - https://github.com/ctran/annotate_models/issues/538#issuecomment-366515716

Can confirm that this works 👍 Thanks [at]ammit

buren avatar Feb 19 '18 19:02 buren

⏫ Same thing with 2.5, Rails 2.5.0.rc1 and annotate 2.7.2.

6temes avatar Mar 17 '18 04:03 6temes

Setting "show_indexes" to false allows this gem to work in Rails 5.2.0

bambery avatar Apr 15 '18 19:04 bambery

This problem already solved but haven't released... 😢 https://github.com/ctran/annotate_models/pull/517

ota42y avatar Apr 16 '18 14:04 ota42y