Active resource find doesn't work in production

Viewed 504

As the title says, I have a simple ActiveResource in my application that is supposed to get data from an api. The collection works perfectly both locally and on the production server. However, .find doesn't work in production, i get a weird error:

MyResource.find(1, params: { website_id: 2 })
ArgumentError: wrong number of arguments (given 2, expected 0..1)

The same query works if I run it from local console connected to the api. API returns a valid response. I have no idea how else to debug it.

class MyResource < ActiveResource::Base
  self.site = Rails.configuration.content_url
  self.prefix = "/api/websites/:website_id/"
  self.element_name = "game"
end

I have to say, i have other resources in the application using the same api, find method works for them, only this one has issues. for some reason it makes a call to

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L330 with 2 arguments, but i can't figure out who makes such call. And it only happens in production mode, not in dev.

2 Answers

I ran into a similar issue in an app that used ActiveRecord for a vendor model and ActiveResource for a delivery model that has a vendor attribute. In development, if the vendor model has not yet been loaded, you can fetch a delivery and deserialize it, including the vendor attribute. If, however, the vendor model has been loaded already, attempting to fetch a delivery leads to the error described in this issue.

How to reproduce in a console:

Vendor.connection
Delivery.find(1)

Seems that AResource is trying to create a new instance of Vendor.

Related