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

Rails 6 + default configuration breaks because of ActionMailbox and ActionText #3157

Closed
klyonrad opened this issue Jun 22, 2019 · 1 comment
Milestone

Comments

@klyonrad
Copy link
Contributor

klyonrad commented Jun 22, 2019

Problem

When rails_admin is configured to show all models, the dashboard breaks. Since Rails 6 code has models for new features (ActionText and ActionMailbox) that define database tables, these two come up as a problem for rails admin when the tables do not actually exist.

Workaround

short variant for users attempting the rails 6 upgrade:

  config.excluded_models << 'ActionMailbox::InboundEmail'
  config.excluded_models << 'ActionText::RichText'

more detailed stuff below

Reproduction

  1. have rails_admin installed without any models configuration
  2. upgrade an application to rails 6 (currently only as release candidate)
  3. open rails_admin dashboard

Error

an error like this occurs (depends on the database):

PG::UndefinedTable - ERROR:  relation "action_mailbox_inbound_emails" does not exist
LINE 8:  WHERE a.attrelid = '"action_mailbox_inbound_emails"'::regcl...

Fix

I took a dive in the source code and I think that I could submit pull request for the fix. However, before I do that, would need to know which direction you find more appropriate. I tried two fixes as monkey patch in the rails_admin initialilzer.

One way could be explicitly excluding these models from the models_pool:

module RailsAdmin
  module Config
    class << self
      def models_pool
        excluded =
          (excluded_models.collect(&:to_s) + %w[RailsAdmin::History
                                                PaperTrail::Version
                                                PaperTrail::VersionAssociation
                                                ActiveStorage::Attachment
                                                ActiveStorage::Blob
                                                ActionMailbox::InboundEmail
                                                ActionText::RichText])
        (viable_models - excluded).uniq.sort
      end
    end
  end
end

But well, it looks like this would just continue to grow and grow.
So maybe when we collect all the models we should filter out the ActiveRecord classes with a call to table_exists?. But I don’t know how big of a performance hit it would be to ask this for dozens of activerecord classes…

module RailsAdmin
  class AbstractModel
    def initialize(model_or_model_name)
      @model_name = model_or_model_name.to_s
      ancestors = model.ancestors.collect(&:to_s)
      # following line is monkey-patched
      if ancestors.include?('ActiveRecord::Base') && !model.abstract_class? && model.table_exists?
        initialize_active_record
      elsif ancestors.include?('Mongoid::Document')
        initialize_mongoid
      end
    end
  end
end

Since I consider this high priority I would start the pull request when you say go, but feel also free to grab the snippets :)

klyonrad added a commit to klyonrad/lazybar that referenced this issue Jun 22, 2019
@mshibuya mshibuya added this to the 2.0.0 milestone Jun 25, 2019
@klyonrad
Copy link
Contributor Author

Thanks for the quick fix! 🥇

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

No branches or pull requests

2 participants