Shopify_app: A copy of Shop has been removed from the module tree but is still active!

Created on 24 Oct 2017  路  10Comments  路  Source: Shopify/shopify_app

I just upgraded from the 7.x line to 8.2.2, and now when I try to install my app I get an error saying "A copy of Shop has been removed from the module tree but is still active!".

The stack trace points to this method in my Shop model:

  def notify_chat
    ChatService.slack_message(chat_message)
  end

And that method is called by a callback defined like this:

after_create_commit :notify_chat

Any ideas why this is happening now when it was fine before?

Most helpful comment

I had it happen during my last upgrade on Feb 7th from shopify_app 7.2.5 to 8.2.5. I was getting the error at Rails boot so Shop must have been referenced someplace early in my Rails bootup sequence (e.g. initializers?).

Switching to 'Shop' as a string fixed it so I haven't tried to dig deeper into it.

All 10 comments

I tried moving this into Shopify::AfterAuthenticateJob and I'm getting a similar error. This time it says "A copy of Shopify::AfterAuthenticateJob has been removed from the module tree but is still active!" and points to this line:

shop = Shop.find_by(shopify_domain: shop_domain)

And, in case it'll help, here's my initializer:

ShopifyApp.configure do |config|
  config.application_name = "Crowdfunder"
  config.api_key = ENV['SHOPIFY_API_KEY']
  config.secret = ENV['SHOPIFY_SECRET']
  config.scope = "read_orders, read_products, write_products, read_script_tags, write_script_tags, read_themes, write_themes"
  config.embedded_app = true
  config.session_repository = Shop

  config.scripttags = [
    {event:'onload', src: "#{ENV['SHOPIFY_APP_BASE']}/scripts/presale.js"}
  ]
  config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
end

@jagthedrummer I bet it's because you have Shop in your initializer. Rails will unload classes (model) and reload them but they are different objects so the initializer's Shop is pointing to a different class object from request to request.

I saw this all the time in Rails 2 when developing engines.

What are the reproduction steps for this? If it is a reloading thing then I assume its not the first request?

@edavis10 That was it, thanks! I changed the relevant line to what's shown below and it started working.

config.session_repository = 'Shop'

Just ran into this again on a new app. I think the install generator should probably generate 'Shop' instead of Shop.

Its fine my script coding is always making me 'shop' without ever getting to shop
It would be nice

@jagthedrummer can you share your steps to reproduce? I've yet to be able to make this occur on my end.

@0ptimusrhyme I don't know _exactly_ what the repro steps are. In both cases I was upgrading an app from 7.something to 8.something, and in both cases I had an after_create callback that would throw that error when I tried to install the app. I'd go to /login, enter the name of my shop, and then on the first redirect back to my local dev env the error would happen. And in both cases just changing the initializer from Shop to 'Shop' would fix it. Sorry I don't have any more info about it. If I run into it again I'll try to take notes on what's going on.

I had it happen during my last upgrade on Feb 7th from shopify_app 7.2.5 to 8.2.5. I was getting the error at Rails boot so Shop must have been referenced someplace early in my Rails bootup sequence (e.g. initializers?).

Switching to 'Shop' as a string fixed it so I haven't tried to dig deeper into it.

Was this page helpful?
0 / 5 - 0 ratings