-
Notifications
You must be signed in to change notification settings - Fork 955
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
ActiveRecord::yaml_new raises DeserializationError if object not found #296
Conversation
… objects from another database
this raise error make unexpected noise |
Hi! If object not found it should be loaded by yaml anyway. And delayed_job should handle this case without raising an exception. |
This is how I solved this problem for DJ2. class ActiveRecord::Base
def self.yaml_new(klass, tag, val)
begin
klass.unscoped.find(val['attributes'][klass.primary_key])
rescue ActiveRecord::RecordNotFound
klass.new.tap{ |obj| obj.assign_attributes(val['attributes'], without_protection: true) }
end
rescue
raise Delayed::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass} , primary key: #{val['attributes'][klass.primary_key]} "
end
end You can easily adapt this solution for DJ3 by doing similar changes in The code isn't 100% bulletproof though. That's why I'm not sending pull-request. But it should work just fine in most cases. |
Actually, I've just found an even easier and much more robust way to achieve consistent deserializing of AR objects. class << ActiveRecord::Base
remove_method :yaml_new
end Which brings me to the point of questioning why did we need AR::Base.yaml_new in the first place. |
DJ is intended to be used with saved AR records. There are a lot of concurrency issues that arise from trying to pass around partial AR objects. |
Regardless of whether or not you should be using DJ with serialized records, this still doesn't have anything to do with the problem at hand, which is that Delayed Job causes the loading of ANY serialized object without a persisted database record to fail, even if that record is being used for something entirely unrelated to Delayed Job. As was stated above, a gem should not affect external application behaviors. This is a real problem, and I'm surprised it hasn't been fixed yet. |
We have the same problem in the past couple of days, this happens when a user creates a record by mistake and immediately deletes it. |
+1 @corwinstephen. |
Ok, I've patched our DJ to deserialize AR models from yaml, without persistence and I have to say that we've had a great deal of hard to track bugs and weirdness because of that. The common case is that DJ tries to perform on a record that was already deleted, calls for references and throws NoMethodError on nil where nils are not supposed to be. So, we had to add special I really think current behavior makes a lot of sense as default. |
I think there's a bit of confusion here. There seem to be at least two separate complaints.
Maybe it's best to close this issue and use #583 to track all of this in one place? |
+1 @corwinstephen To me this seems to be a very important issue. I would love to discuss about any improvements that I could make to get #583 merged, and the most interesting of my approach is that it doesn't change how DJ deserialize objects at all. |
+1 @jezstephens |
Sorry if this is a stupid question, but what's the best way to reference Or is there a better tag or branch to pull that pull request into my On Wed, Dec 11, 2013 at 7:24 AM, Brenno Costa notifications@github.comwrote:
Wes Sheldahl |
@sockmonk gem 'delayed_job', github: 'brennovich/delayed_job'
gem 'delayed_job_active_record' |
Ok, using the v3 branch in my Gemfile like this seemed to work fine; the test suite ran without any of the YAML-related failures.:
But when I changed my Gemfile to this and re-ran the test suite:
Then the YAML-related failures came back, as though I were using the official gem. |
@sockmonk which is your ruby version? For me Edit: Actually I just dropped my commit from branch |
Also, I'm testing with Rails 3.2.16. |
+1 |
This silently overrides yaml standard logic thus breaks existing functionality (it is not required by yaml to have a persistent ar object to be able to load it from yaml representation by default and this should not be changed by a gem).
This is basically the same request with this one: #282 but a bit refactored. The pull request was closed but not implemented previously. So the BUG is still present in the master branch.