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

undefined method `id' for {}:Policy #23

Open
traels opened this issue Apr 21, 2015 · 2 comments
Open

undefined method `id' for {}:Policy #23

traels opened this issue Apr 21, 2015 · 2 comments

Comments

@traels
Copy link

traels commented Apr 21, 2015

I know I just posted this as a comment to another issue, but found that this might be something entirely different.
I'm using Rfm models and after a Policy.create (or .new followed by as save) I got "undefined method `id' for {}:Policy". When accessing .id on my instance.
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 :-(
I am using the newest version of Rfm.
I've set it to log requests, no request is registered in my Rails app, and nothing is registered in FM, it is like new/initialize in rfm record can fail and just return a blank hash. I see there is some commented out rescue code that seems to indicate that it has been an issue before. I'd really like to solve this, and I'll be glad to cook up a PR on this, but I need some hints to where I should go look for this issue.
I would hate to go back to write FM we stuff in PHP :-(

@traels
Copy link
Author

traels commented May 12, 2015

Have now found some more info - this started happening in a new project - in development.
Failing flow:
CChild.find({parent_id: 123}).first # which returns nothing, and should
c = CChild.new
c.name = 'Simon' # undefined method :name for {}:CChild (in Rfm::Base line 255)

To make it work: (that is, after restarting console!)
CChild.new
CChild.find({parent_id: 123}).first # which returns nothing, and should
c = CChild.new
c.name = 'Simon'
Now everything works ... !!!

My guess is that somewhere along the road the first call to a layout will cache the field names, and if no field names are returned then that class will be (forever?) useless.

Any help on fixing this will be greatly appreciated - for now I think I'll just do a .new for each of my models in an initializer to make sure all classes have cached some fieldnames :)

@ginjo
Copy link
Owner

ginjo commented Sep 9, 2015

@traels, this sounds like a similar or same issue as #28. Since the title of that issue is more likely to capture the audience having that issue, I'm following up in that thread. If you think your issue is different, do let me know.
Thanks

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