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

ActiveJob Integration #663

Closed
hayesgm opened this issue Apr 2, 2015 · 4 comments · Fixed by #928
Closed

ActiveJob Integration #663

hayesgm opened this issue Apr 2, 2015 · 4 comments · Fixed by #928

Comments

@hayesgm
Copy link

hayesgm commented Apr 2, 2015

Draper decorators do not currently implement globalid. The fix is just to call in an initializer:

Draper::Decorator.send(:include, GlobalID::Identification) if defined?(GlobalID)

As rails includes globalid by default, would we want to add this line to the repo or put it in the documentation?

Without this fix, calling UserMailer.welcome(user.decorate).deliver_later will raise ActiveJob:: SerializationError, due to this code.

@mikedao
Copy link
Contributor

mikedao commented Apr 3, 2015

Modifying the documentation allows for an extremely quick fix. What are your arguments for/against?

@EtienneDepaulis
Copy link

This fix might be misleading. It works great to to silence the ActiveJob:: SerializationError but as it retrieves the object from DB again later, the object is not decorated anymore, thus preventing from using added methods in the emails.

@codebycliff
Copy link
Collaborator

While this might be misleading, you should still be able to pass a decorated object to a background job without it blowing up. Ideally, a decorated object should behave as if it were the object it is decorating. Here's what I'm proposing:

  1. Add: include GlobalID::Identification if defined? GlobalID to Draper::Decorator so that it doesn't blow up.
  2. Add some documentation to the README saying: "While you can pass a decorated object to background jobs, the object won't be decorated when it is deserialized."

Is anyone opposed to this solution?

codebycliff added a commit that referenced this issue Sep 11, 2017
* Add note on Active Job integration for #663

* Implement GlobalID by delegating to object and add documentation.

* Update readme and add missing require statement.

* Actually include the module.

* Create post instead of assuming it exists.

* Add test for #to_global_id.
@codebycliff
Copy link
Collaborator

Closing this as I believe it is resolved. If someone figures out how to deserialize the record as a decorated object, feel free to open a pull request.

Alexander-Senko added a commit to Alexander-Senko/draper that referenced this issue Feb 6, 2024
Implementing `Decorator.find` improves compatibility with Global ID and
allows one to use decorated objects in jobs seamlessly.

Resolves drapergem#663.
Improves drapergem#817.
Alexander-Senko added a commit to Alexander-Senko/draper that referenced this issue Aug 30, 2024
Implementing `Decorator.find` improves compatibility with Global ID and
allows one to use decorated objects in jobs seamlessly.

Resolves drapergem#663.
Improves drapergem#817.
Alexander-Senko added a commit to Alexander-Senko/draper that referenced this issue Sep 1, 2024
Implementing `Decorator.find` improves compatibility with Global ID and
allows one to use decorated objects in jobs seamlessly.

Resolves drapergem#663.
Improves drapergem#817.
Alexander-Senko added a commit that referenced this issue Sep 1, 2024
Implementing `Decorator.find` improves compatibility with Global ID and
allows one to use decorated objects in jobs seamlessly.

Resolves #663.
Improves #817.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants