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

Unable to annotate models due to undifenid method and no implicit coversion #743

Open
robbevp opened this issue Jan 27, 2020 · 3 comments
Open

Comments

@robbevp
Copy link

robbevp commented Jan 27, 2020

I'm currently not able to annotate my models (routes seem to work fine).
I've resetted the auto_annotate_models.rake, based on #663 but without any luck

Commands

$ bundle exec annotate --models
Unable to annotate app/models/post.rb: undefined method `gsub' for nil:NilClass
Unable to annotate app/models/post.rb: no implicit conversion of nil into Array
[...]
Model files unchanged.

This error is present for all models that have changed.

If I run with trace:

$ bundle exec annotate --models --trace
Unable to annotate app/models/auth_token.rb: undefined method `gsub' for nil:NilClass
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:475:in `block in get_foreign_key_info'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:477:in `map'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:477:in `get_foreign_key_info'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:321:in `get_schema_info'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:625:in `annotate'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:822:in `annotate_model_file'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:798:in `block in do_annotations'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:797:in `each'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:797:in `do_annotations'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/bin/annotate:31:in `<top (required)>'
        [...]/vendor/bundle/ruby/2.6.0/bin/annotate:23:in `load'
        [...]/vendor/bundle/ruby/2.6.0/bin/annotate:23:in `<top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
        /Users/robbevp/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
Unable to annotate app/models/auth_token.rb: no implicit conversion of nil into Array
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:822:in `concat'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:822:in `annotate_model_file'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:798:in `block in do_annotations'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:797:in `each'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/lib/annotate/annotate_models.rb:797:in `do_annotations'
        [...]/vendor/bundle/ruby/2.6.0/gems/annotate-3.0.3/bin/annotate:31:in `<top (required)>'
        [...]/vendor/bundle/ruby/2.6.0/bin/annotate:23:in `load'
        [...]/vendor/bundle/ruby/2.6.0/bin/annotate:23:in `<top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
        /Users/robbevp/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
        /Users/robbevp/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
        /Users/robbevp/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'

(I've shortened all references to my apps folder since its path is quite long)

Version

  • annotate v3.0.3
  • rails v6.0.2.1
  • ruby 2.6.5
@drwl
Copy link
Collaborator

drwl commented Feb 1, 2020

@robbevan can you share your model/post.rb file?

@robbevp
Copy link
Author

robbevp commented Feb 2, 2020

@drwl sure

class Post < ApplicationRecord
  belongs_to :theme
  belongs_to :user, optional: true
  has_one :theme_where_current_post, class_name: 'Theme', foreign_key: 'current_post_id', dependent: :nullify, inverse_of: :current_post
  has_many :comments, dependent: :destroy

  validates :content, presence: true
  validates :theme_id, presence: true
  validate :post_cannot_be_hidden_when_themes_current_post

  def current?
    true if !id.nil? && theme.current_post_id == id
  end

  def title
    if theme.organizationname?
      Rails.configuration.organization['name']
    elsif theme.postauthor?
      author if !theme.notpermitted? && author?
    elsif theme.themetitle?
      theme.name
    end
  end

  private

  def post_cannot_be_hidden_when_themes_current_post
    errors.add(:visible, :current_post_cannot_be_hidden) if current? && visible == false
  end
end

Note that I get the exact same errors on three other models

@robbevp
Copy link
Author

robbevp commented Feb 2, 2020

I was just playing around with some settings in auto_annotate_models.rb and it does work if I set show_foreign_keys to false.
However the only common thing I can find is that they all have a belongs_to and my other models don't

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

No branches or pull requests

2 participants