rfm icon indicating copy to clipboard operation
rfm copied to clipboard

NoMethodError: undefined method `name' for Hash

Open david-boyd opened this issue 11 years ago • 3 comments

We have found an intermittent issue that we cannot reproduce however wondering if anyone can shed some light on this.

The issue is in line 129 of record.rb field_name = @layout.field_mapping[field.name] || field.name rescue field.name

If I understand this correctly field is a hash that has been extended to add a method .name. Using core_ext.rb rfm_extend_members - def each adding Fmpxmlresult::Resultset::Column

The error below shows that the Hash doesn't have the method .name

NoMethodError: undefined method name' for {"name"=>"addr_full", "data"=>{"__content__"=>" NSW "}}:Hash /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:129:inrescue in block in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:129:in block in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:127:ineach' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:127:in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:111:innew' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:111:in rescue in new' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:108:innew' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:171:in block in build_records' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/utilities/core_ext.rb:94:inblock in each' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/utilities/core_ext.rb:91:in each' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/utilities/core_ext.rb:91:ineach' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:170:in build_records' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/resultset.rb:128:ininitialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/layout.rb:285:in new' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/layout.rb:285:inget_records' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/layout.rb:179:in all' /data/myi/releases/20140407053924/app/jobs/load_fm_job.rb:101:inblock in sync_parents' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/mongoid-3.1.6/lib/mongoid/unit_of_work.rb:39:in unit_of_work' /data/myi/releases/20140407053924/app/jobs/load_fm_job.rb:77:insync_parents' /data/myi/releases/20140407053924/app/jobs/load_fm_job.rb:16:in perform' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:inpublic_send' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in dispatch' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:67:indispatch' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in block in handle_message' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:inblock in task' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in block in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:inblock in create'

We are simply doing a FMLayout.all call. It's really weird it doesnt happen all the time, it only happens sometimes in our production system. During our nightly Sync. Also other .all calls work for other layouts.

Really stuck here only thing i can think to do is hack record.rb line 129 from field_name = @layout.field_mapping[field.name] || field.name rescue field.name to field_name = @layout.field_mapping[field.name] || field.name rescue field[name]

david-boyd avatar May 09 '14 06:05 david-boyd

Ok... been a lot of changes recently in the underlying parsing engine of rfm. Give the latest master branch a try - I suspect this issue will be gone. If not, see if you can post an example fmrestulset.xml that demonstrates the issue. Thanks.

ginjo avatar Aug 05 '14 22:08 ginjo

Cheers William, we are testing out version 3. I will let you know if we see the issue again.

david-boyd avatar Aug 06 '14 00:08 david-boyd

I've just had the same kind of error. I'm using Rfm models and after a Policy.create I got "undefined method `id' for {}:Policy". It has happend a few times, no exceptions are raised in Rfm, the model is just an empty hash after create. I created a few tests and ran it alot of times and it did not happen, so far I've only seen it in production :-(

traels avatar Apr 16 '15 17:04 traels