Skip to content
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

Fix unable to annotate error when table_name is frozen #517

Merged
merged 1 commit into from
Oct 11, 2017
Merged

Fix unable to annotate error when table_name is frozen #517

merged 1 commit into from
Oct 11, 2017

Conversation

ryu39
Copy link
Contributor

@ryu39 ryu39 commented Oct 11, 2017

I found that annotate command is failed when table_name of model class is frozen.
Please see the sample model class code.

# frozen_string_literal: true

class User < ApplicationRecord
  self.table_name = 'tbl_users'
end

When annotate command is executed to the model file, it is failed with following message .
(Messages with --trace option are backtraces.txt.)

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

This is seemed to be caused by this line.
table_name.to_s.slice!(klass.table_name_prefix) changes table_name string itself, but table_name is frozen(by frozen_string_literal magic comment), so can't modify frozen String error is raised.

I fixed this error. Please check this PR.

Copy link
Owner

@ctran ctran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, that was some lousy coding!

@ctran ctran merged commit 2a977bf into ctran:develop Oct 11, 2017
@ctran ctran added this to the v2.7.3 milestone Oct 11, 2017
@ctran ctran added the bug label Oct 11, 2017
@qsona
Copy link

qsona commented Jan 11, 2018

@ctran hi, I had trouble with same problem (on Rails 5.2) and found it's already fixed with this PR. Could you please release it sooner? Thank you for your great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants