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

Ensure type-safe serialization/deserialization of total time #405

Closed
wants to merge 1 commit into from

Conversation

wandering-tales
Copy link

Under unknown circumstances, the extra total_time argument passed to instances of jobs is serialized/deserialized as a string instead of a float. That causes a TypeError due to an impossible type conversion.

Now the total_time argument is coerced to a float number prior its serialization and deserialization, respectively.

Fixes #396.

Under unknown circumstances, the extra `total_time` argument passed to
instances of jobs is serialized/deserialized as a string instead of a
float. That causes a `TypeError` due to an impossible type conversion.

Now the `total_time` argument is coerced to a float number prior its
serialization and deserialization, respectively.
@wandering-tales
Copy link
Author

I have signed the CLA!

"total_time" => total_time,
"total_time" => total_time.to_f,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should not be necessary if we're always casting it on deserialization, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not necessary. Simply added for completeness.

)
end

def deserialize(job_data) # @private
super
self.cursor_position = job_data["cursor_position"]
self.times_interrupted = job_data["times_interrupted"] || 0
self.total_time = job_data["total_time"] || 0
self.total_time = job_data["total_time"].to_f || 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Float(...) here, instead of .to_f? It has better error messages when it's fed things that are not floats. We do need to be careful with nil in that case:

Suggested change
self.total_time = job_data["total_time"].to_f || 0.0
self.total_time = Float(job_data["total_time"] || 0.0)

@Mangara
Copy link
Contributor

Mangara commented Jul 21, 2023

Apologies, you'll need to rebase to get CI to run properly, as there were some lint error that I fixed recently.

@Mangara
Copy link
Contributor

Mangara commented Aug 16, 2023

Closed in favour of #417

@Mangara Mangara closed this Aug 16, 2023
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

Successfully merging this pull request may close these issues.

Error on serialization/deserialization of total time
2 participants