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

Serializes time objects in a lossy fashion leading to failure to look up the record from the DB #191

Open
erikbelusic opened this issue Dec 13, 2024 · 0 comments

Comments

@erikbelusic
Copy link

erikbelusic commented Dec 13, 2024

When passing a model instance with a CPK and a timestamp as part of the CPK into ActiveJobs an error is raised that the record cannot be found during deserialization. I tracked this down to lossy encoding of timestamps. Using to_s on the timestamp drops milli/micro/nano second precision which is often stored in the DB, which causes a failure to find the record.

➜ irb
3.3.5 :001 > require "active_support/all"
 => true
3.3.5 :002 > t1 = Time.current
 => 2024-12-12 22:48:28.030654 -0500
3.3.5 :003 > t2 = Time.parse(t1.to_s)
 => 2024-12-12 22:48:28 -0500
3.3.5 :004 > t1 == t2
 => false

I'd suggest converting time objects to a string with .iso8601(9) as that seems to be the highest precision we will encounter on timestamps. I am happy implement this fix if someone can provide guidance on a preference between checking the class type of the id part or checking if it responds to iso8601. Also if there is a preferred testing strategy for something like this.

Extra context on the use case. I have records in TimescaleDB hypertables that often have primary keys of [:created_at, :key].

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

1 participant