Annotate no longer works with Rails 5.2 models
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
Have you tried it the dev version of annotate gem (see README for instructions)?
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!
@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.
@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.
I have same issue with following versions.
ruby 2.5.0
rails 5.2.0.beta2
annotate 2.7.2
Same here, with same versions as @fshin1988 except rails 5.2.0.rc1
@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.
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
⏫ Same thing with 2.5, Rails 2.5.0.rc1 and annotate 2.7.2.
Setting "show_indexes" to false allows this gem to work in Rails 5.2.0
This problem already solved but haven't released... 😢 https://github.com/ctran/annotate_models/pull/517