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

Deal with chrono deprecations #951

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

Lorak-mmk
Copy link
Collaborator

@Lorak-mmk Lorak-mmk commented Mar 6, 2024

Chrono deprecated several method in 0.4.35 / 0.4.34

  • chrono::Duration::days -> chrono::Duration::try_days New method was introduced in 0.4.33, so quite recently. This requires us to bump minimum chrono version.

  • NaiveDateTime::from_timestamp_opt -> DateTime::from_timestamp This requires some other changes, because of the switch from NaiveDateTime to DateTime.

  • NaiveDateTime::timestamp_millis -> .and_utc().timestamp_millis()

I also added a comment explaining the implementation of CqlValueDisplayer and why it doesn't use existing impl TryInto<NaiveDate> for CqlDate.

Fixes: #950

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@Lorak-mmk Lorak-mmk requested review from piodul and wprzytula March 6, 2024 21:10
@Lorak-mmk Lorak-mmk self-assigned this Mar 6, 2024
@Lorak-mmk Lorak-mmk force-pushed the fix-chrono-duration-days branch from 3893ba6 to 0058d93 Compare March 6, 2024 21:28
Chrono deprecated several method in 0.4.35 / 0.4.34

- chrono::Duration::days -> chrono::Duration::try_days
  New method was introduced in 0.4.33, so quite recently.
  This requires us to bump minimum chrono version.

- NaiveDateTime::from_timestamp_opt -> DateTime::from_timestamp
  This requires some other changes, because of the switch from
  NaiveDateTime to DateTime.

- NaiveDateTime::timestamp_millis -> .and_utc().timestamp_millis()

I also added a comment explaining the implementation of CqlValueDisplayer
and why it doesn't use existing `impl TryInto<NaiveDate> for CqlDate`.
@Lorak-mmk Lorak-mmk force-pushed the fix-chrono-duration-days branch from 0058d93 to 8648c3b Compare March 6, 2024 21:35
@Lorak-mmk
Copy link
Collaborator Author

New APIs were added in 0.4.32, not 0.4.33 - updated the PR accordingly after verifying that it works after cargo update chrono --precise 0.4.32.

@wprzytula wprzytula requested a review from muzarski March 7, 2024 07:53
scylla-cql/src/frame/value_tests.rs Outdated Show resolved Hide resolved
Comment on lines +69 to +73
// This is basically a copy of the code used in `impl TryInto<NaiveDate> for CqlDate` impl
// in scylla-cql. We can't call this impl because it is behind chrono feature in scylla-cql.

// date_days is u32 then converted to i64 then we subtract 2^31;
// Max value is 2^31, min value is -2^31. Both values can safely fit in chrono::Duration, this call won't panic
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we anyway use chrono in scylla unconditionally, why we even put it under feature in scylla_cql? What benefit could one have from disabling chrono in scylla_cql when it's still required in scylla ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe less code generated for scylla-cql?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to be a very small gain compared to complexity added. Especially that, as you can see, we handle CqlDate with chrono anyway.

Tests doesn't serialize NaivedateTime, it serializes DateTime.
It's not possible for it to serialize NaiveDateTime,as there is no such
serialization implementation. Rename the test to reflect reality.
@wprzytula wprzytula merged commit 44785bd into scylladb:main Mar 7, 2024
11 checks passed
@Lorak-mmk Lorak-mmk mentioned this pull request May 9, 2024
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.

Clippy fails because of chrono deprecation
2 participants