annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

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

Open robbevp opened this issue 5 years ago • 3 comments

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

robbevp avatar Jan 27 '20 19:01 robbevp

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

drwl avatar Feb 01 '20 20:02 drwl

@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 avatar Feb 02 '20 09:02 robbevp

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

robbevp avatar Feb 02 '20 09:02 robbevp