How to reproduce/sanitize messy POST params to avoid YAML serialization issues with delayed_job?

喜欢而已 提交于 2019-12-02 01:42:26

A detailed explanation of what @house9 is suggesting:

Do NOT do the following (even though the delayed_job's git repo suggests is as example)

Notifier.delay.signup(@user)

class NotifierMailer < ActionMailer::Base
  def signup(user)
  end
end

as this will attempt to yaml encode @user (which can cause issues)

But rather, any time you have an object (especially an AR object) that has an id, you should pass the id when calling the delayed job and retrieve it later:

Notifier.delay.signup(@user.id)

class NotifierMailer < ActionMailer::Base
  def signup(id)
     @user = User.find_by_id(id)
  end
end

Any idea how I should sanitize my params to avoid such a problem?

Do not serialize your activerecord objects, instead just serialize the AR id, then do a find as the first step in the job.

Not sure why your serialized AR is corrupted, did your schema change between the time the serialization occured and before the job ran?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!