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

rails/active job: Time casting fails #247

Closed
siegy22 opened this issue May 20, 2019 · 7 comments
Closed

rails/active job: Time casting fails #247

siegy22 opened this issue May 20, 2019 · 7 comments

Comments

@siegy22
Copy link
Member

siegy22 commented May 20, 2019

Using rails 6.0.0.rc1 and pg 1.1.4:

  • rails new foo && cd foo
  • (Add que to Gemfile, set active_job.queue_adapter = :que generate migration, migrate database)
  • rails g job example
  • rails runner ExampleJob

Resulting in:

Loading development environment (Rails 6.0.0.rc1)
irb(main):001:0> ExampleJob.perform_later
Enqueued ExampleJob (Job ID: 96741bc2-47a8-4efc-b768-bfab1e4395e5) to Que(default)
Traceback (most recent call last):
        1: from (irb):1
TypeError (no implicit conversion of Time into String)
@siegy22
Copy link
Member Author

siegy22 commented May 20, 2019

My assumption is that pg (since whatever version) automatically does the casting.

The following patch fixes this.

@@ -152,7 +152,11 @@ module Que
       },
 
       # Timestamp with time zone
-      1184 => Time.method(:parse),
+      1184 => -> (value) {
+        return value if value.is_a?(Time)
+
+        Time.parse(value)
+      },
     }
 
     # JSON, JSONB

cushingw added a commit to cushingw/que that referenced this issue Jun 10, 2019
@chanks
Copy link
Collaborator

chanks commented Jun 28, 2019

Fixed in master.

@9mm
Copy link

9mm commented Sep 6, 2019

Is it possible to also fix this on 0.x branch? We use this in production and 1.0 wasnt stable enough, but it looks like it was only fixed on 1.0 beta

@danielpclark
Copy link

danielpclark commented Mar 5, 2020

For those using one of the later versions of the 0.x releases with Rails you can create a file config/initializers/que.rb and place the following in it.

Que::Adapters::Base::CAST_PROCS[1184] = lambda do |value|
  case value
  when Time then value
  when String then Time.parse(value)
  else raise "Unexpected time class: #{value.class} (#{value.inspect})"
  end
end

This will patch the issue when upgrading to Rails 6.

@newbenji
Copy link

Is it possible to also fix this on 0.x branch? We use this in production and 1.0 wasnt stable enough, but it looks like it was only fixed on 1.0 beta

Anything about 1.0 is ready?
and what issue did you see with 1.0...

@siegy22
Copy link
Member Author

siegy22 commented Apr 23, 2020

@newbenji Check the 1.0 milestone: https://github.com/que-rb/que/milestone/1

@LukeClancy
Copy link

LukeClancy commented Dec 24, 2020

This breaks que-web as well by the way, and the fix doesn't work for it
Screenshot from 2020-12-23 17-55-58
Although I think the job itself still works... will update when it runs

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

6 participants