I have upgraded my Ruby to 2.5 and after rectifying many dependency issues, I'm stuck at a place.
There is save method being called which saves the records, but somehow it do not works now and shows following error:
500 Internal Error
undefined method 'fetch_value' for #<Hash:0*0007e589e>
Did you mean fetch_values
each_value:
Earlier the same .save was working perfectly fine.
I've seen the same exception before. In my case, some ActiveRecord models were marshaled via Marshal::dump and saved as binary stream. Then, Ruby and Rails were upgraded.
Afterwards, calling Marshal::load on the marshaled copies would retrieve them and object.class would show the right model's name, but accessing any attribute within would throw the same exception.
I had to clear the marshaled copies and generate new ones.
Related
I'm currently unable to use any of the active support time methods inside my ruby on rails 5.0 model like the following:
5.seconds
2.days
10.minutes
throws an error:
NoMethodError: undefined method `seconds' for AS::Duration:0x007f97a5903b90 #value=5, #parts=[[:seconds, 5]] Did you mean? send
EDIT: here is the actual code causing an issue.
ReminderJob.set(wait: 5.seconds).perform_later(self.user.id)
Even tho I can see people using the below code fine and it works
UserReminderJob.set(wait: 1.week).perform_later user
However, it works in my console and in my controllers and views.
The error message states that the object is AS::Duration:0x007f97a5903b90, NOT an integer -- therefore the example of 5.seconds will not reproduce the problem.
This is also unusual, since 5.seconds will normally return an ActiveSupport::Duration object, not AS::Duration.
I would therefore hazard a guess that you're actually using the as-duration ruby gem rather than built-in rails behaviour. This extends the the Integer class in a different way, and returns an object that doesn't behave like an integer.
I think that an actual reproduction of your error could be achieved with: 5.seconds.seconds. In standard rails, this works fine (and returns the same value as 5.seconds), since ActiveSupport::Duration instances behave like Integers. But with this gem, it fails with the above error.
Rails 4.2.3, IdentityCache gem 0.2.5
I am calling ZipCodeLookup.fetch_by_id(value) and I am getting the following error:
undefined method `fetch_value' for #<Hash:0x007fbc6d261e08>
I have the following attributes in my ZipCodeLookup model
include IdentityCache
cache_index :zip_code, unique: true
I haven't seen anyone else with this issue. Does anyone know how to fix this?
fyi works in Rails 4.1.x
the error came from not clearing the cache. so run the following command in the rails console: IdentityCache.cache.clear
I've seen the same exception before without using IdentityCache. In my case, some ActiveRecord models were manually marshaled via Marshal::dump and saved as binary stream. Then, Ruby and Rails were upgraded.
Afterwards, calling Marshal::load on the marshaled copies would retrieve them and object.class would show the right model's name, but accessing any attribute within would throw the same exception.
I had to clear the marshaled copies and generate new ones.
I am getting a couple different errors at a particular line of code in one of my models when running in Sidekiq-queued jobs. The code in question is:
#lookup_fields[:asin] ||= self.book_lookups.find_by_name("asin").try(:value)
I either get undefined method 'scope' for #<ActiveRecord::Associations::AssociationScope:0x00000005f20cb0> or undefined method 'aliased_table_for' for #<ActiveRecord::Associations::AliasTracker:0x00000005bc3f90>.
At another line of code in another Sidekiq job, I get the error undefined method 'decrypt_and_verify' for #<ActiveSupport::MessageEncryptor:0x00000007143208>.
All of these errors make no sense, as they are standard methods of the Rails runtime support libraries.
The model in question has a :has_many association defined for the "book_lookups" model, "name" and "value" are fields in the "book_lookups" model. This always happens on the first 1-3 records processed. If I run the same code outside of a Sidekiq job, these errors do not occur.
I cannot reproduce the error on my development machine, only on production which is hosted at Heroku.
I may have "solved" the first set of errors by putting the code `BookLookup.new()' in an initializer, forcing the model to load before Sidekiq creates any threads. Only one night's work to go on, so we'll have to see if the trend continues...
Even if this solves the immediate problem, I don't think it solves the real underlying issue, which is classes not getting fully loaded before being used. Is class-loading an atomic operation? Is it possible for one thread to start loading a class and another to start using the class before it is fully loaded?
I believe that I have discovered the answer: config.threadsafe!, which I had not done. I have now done that and most if not all of the errors have disappeared. References: http://guides.rubyonrails.org/configuring.html, http://m.onkey.org/thread-safety-for-your-rails (especially the section "Ruby's require is not atomic").
I been working on porting my application on "Rails 3.0.7" ,ever since I started to employ caching for my application either (file cache,memcache or any other) . I always happen to get the above error "can't dump File" .
I Google a bit and found that it has something to do with Marshal dump as ruby interpreter does allow Marshal dump of object that have Procs or lambdas in them so I looked upon my code but I could not find any Proc and lambda in my whole applications
Now to discover the problem I drill down the ActiveRecord 3.0.7 code and here are few interesting finding that I came up with
1 . "includes" in Rails 3 + internally call the define name scope OK this I give the answer that there is Proc and Lambada associated with the object so the error but this doesn't explain why the same code work sometime and report with errors(above errors) other times I mean If the error is for the Marshalling and object that hold a Proc or a Lambada then code should definitely not work and should always report errors no matter how many times the same code is ran but that not the case over here the code return errors sometimes and work well other times
Code
Rails.cache.fetch("accessible_websites_1")
{ Website.includes(:account) }
2 . If the ".includes" in Rails 3.0 + has problem then what up with other 'include' syntax does it too report error (above error)
so I ran the code with older syntax of include
Here is it
Rails.cache.fetch("accessible_websites_1")
{ Website.all(:include =>
:account) }
well surprisingly it ran but it never preloaded the account related for all the website ( which is where weird) but at least It never gave and error
so did a forensic on Active Record 3.0 + once again to discover how the older version of include(Rails 2.3 +) work surprise to know that the older version of include syntax internally call the .includes method of ActiveRecord 3.0 +
whoo How is that possible
two different syntax both call the same internal method one report with error sometimes ( not every time but preload the associated object) and other does not report with error but neither preload the associated object as said earlier.
OK , Hearing all this if anyone can help me out then I would be utmost grateful
By the way
Here what I'm trying to achieve
Rails.cache.fetch("accessible_websites_1")
{ Website.includes(:account) }
the equivalent code of above in Rails 2.3.5 and Rails 3 + (but does not preload the associated account object of all websites)
i.e
Rails.cache.fetch("accessible_websites_1")
{ Website.find(:all,:include =>
:account) }
Work perfectly fine without any issue
I using
Ruby = "ruby 1.8.7 (2010-01-10
patchlevel 249) [i486-linux]" Rails
= " Rails 3.0.7"
The same Problem even persisted on Rails 3.1.0
am I missing something
I can also provide the model structure if required
The problem is that
Website.includes(:account)
does not load the data, it just provides you with a proxy object that will load the objects on demand when you do something like calling #each or #to_s, if you force the fetching by adding a #to_aat the end it should work, e.g. try
Marshal.dump(Website.includes(:account))
Marshal.dump(Website.includes(:account).to_a)
#all(x=>y) does not do the same thing as #x(y), that is why you can do X.includes.joins.where but not X.all.where.
Not sure where the reference to a File comes from though.
I have a rails project that uses an old versions of the FlexImage plug-in to handle images.
In the old version that image data was stored in a column called "data", in the new version that column must be named "image_file_data".
I wrote a migration to rename the column, but when I try to run the migration, my guess is that rails tries to load the models, which then automatically check to see if the valid column is there (which it isn't) and that throws an error which halts the migration.
I would guess that my problems would be solved if I never loaded the model classes in question and just wrote some sql to rename the columns. But the following line doesn't work, since rails still tries to load the model.
Apartment.connection.execute "ALTER TABLE logos CHANGE DATA image_file_data MEDIUMBLOB;"
Oops, I figured it out. I was calling
model = (table_name.to_s).classify.constantize
Earlier, and this was causing the model to load