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

Datetime field in "returning" sends back string and not casted ActiveSupport::TimeWithZone value. #693

Open
skunkworker opened this issue Jul 29, 2020 · 1 comment

Comments

@skunkworker
Copy link

I'm using 1.0.5 with Postgres 12.3.

user_hashes = {name: "John", verified_at: Time.now }
outcome = User.import( user_hashes, validate: false, returning: [:name, :verified_at] )
puts outcome.results =>
  [ 1, "John", "2020-07-29 11:19:57.111111" ]

When returning a datetime field in the :returning block, the field will come back as a string and not as a casted date.

I've got an additional method that calls ::User.type_for_attribute(:verified_at).cast(value) which returns an ActiveSupport::TimeWithZone object but I am unsure if this is intentional behavior or just a bug, the rest of the columns appear to be properly cast though.

@skunkworker skunkworker changed the title Datetime field in "returning" sends back string and not casted value. Datetime field in "returning" sends back string and not casted ActiveSupport::TimeWithZone value. Jul 29, 2020
@jkowens
Copy link
Collaborator

jkowens commented Sep 24, 2020

No typecasting is done on the returning values within ActiveRecord-Import. If you would like to investigate adding support for that, I think that would be a nice feature...but I also don't think it's completely unreasonable require casting/parsing the returning values either.

Have you done any benchmarks to see how parsing compares to casting in your example?

DateTime.parse(value).in_time_zone

vs.

User.type_for_attribute(:verified_at).cast(value)

Here is where I would start looking:

results << returning_indexes.map { |i| value_array[i] }

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