From 0058d9347314f09c54705dd5e02b5e786420c1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Bary=C5=82a?= Date: Wed, 6 Mar 2024 22:09:56 +0100 Subject: [PATCH] Deal with chrono deprecations 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 for CqlDate`. --- Cargo.lock.msrv | 145 +++++++++++++++++------- scylla-cql/Cargo.toml | 2 +- scylla-cql/src/frame/response/result.rs | 4 +- scylla-cql/src/frame/value.rs | 2 +- scylla-cql/src/frame/value_tests.rs | 25 ++-- scylla/Cargo.toml | 2 +- scylla/src/transport/cql_types_test.rs | 5 +- scylla/src/utils/pretty.rs | 7 +- 8 files changed, 125 insertions(+), 67 deletions(-) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index 05324b38b0..eafc5cc234 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ "gimli", ] @@ -95,9 +95,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" dependencies = [ "addr2line", "cc", @@ -180,14 +180,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.30" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets", + "windows-targets 0.52.4", ] [[package]] @@ -269,9 +269,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "criterion" @@ -634,9 +634,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" [[package]] name = "half" @@ -768,9 +768,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -859,9 +859,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -995,9 +995,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "memchr", ] @@ -1084,7 +1084,7 @@ dependencies = [ "libc", "redox_syscall 0.3.5", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1270,9 +1270,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags 1.3.2", ] @@ -1293,7 +1293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom", - "redox_syscall 0.2.16", + "redox_syscall 0.2.13", "thiserror", ] @@ -2012,9 +2012,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2022,24 +2022,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.32", + "syn 1.0.109", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2047,28 +2047,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", @@ -2111,7 +2111,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2120,7 +2120,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2129,13 +2129,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -2144,42 +2159,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "winnow" version = "0.5.15" diff --git a/scylla-cql/Cargo.toml b/scylla-cql/Cargo.toml index edbfcd3c8f..0a79e9aaa3 100644 --- a/scylla-cql/Cargo.toml +++ b/scylla-cql/Cargo.toml @@ -21,7 +21,7 @@ thiserror = "1.0" num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true } num-bigint-04 = { package = "num-bigint", version = "0.4", optional = true } bigdecimal-04 = { package = "bigdecimal", version = "0.4", optional = true } -chrono = { version = "0.4.27", default-features = false, optional = true } +chrono = { version = "0.4.33", default-features = false, optional = true } lz4_flex = { version = "0.11.1" } async-trait = "0.1.57" serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 95cc4bea17..75c7a15058 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -1580,10 +1580,10 @@ mod tests { #[cfg(feature = "chrono")] #[test] fn test_datetime_from_cql() { - use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; + use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime}; // 0 when converted to DateTime is 1970-01-01 0:00:00.00 - let unix_epoch = NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc(); + let unix_epoch = DateTime::from_timestamp(0, 0).unwrap(); let date = super::deser_cql_value(&ColumnType::Timestamp, &mut 0i64.to_be_bytes().as_ref()) .unwrap(); diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 991d9ad59d..dd5212c25b 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -489,7 +489,7 @@ impl TryInto for CqlDate { // 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 - let duration_since_unix_epoch = chrono::Duration::days(days_since_unix_epoch); + let duration_since_unix_epoch = chrono::Duration::try_days(days_since_unix_epoch).unwrap(); NaiveDate::from_yo_opt(1970, 1) .unwrap() diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index debf979249..c839f076dc 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -490,46 +490,45 @@ fn cql_timestamp_serialization() { #[cfg(feature = "chrono")] #[test] fn naive_date_time_serialization() { - use chrono::NaiveDateTime; - let test_cases = [ + use chrono::{DateTime, Utc}; + let test_cases: [(DateTime, [u8; 8]); 7] = [ ( // Max time serialized without error - NaiveDateTime::MAX, - NaiveDateTime::MAX.timestamp_millis().to_be_bytes(), + DateTime::::MAX_UTC, + DateTime::::MAX_UTC.timestamp_millis().to_be_bytes(), ), ( // Min time serialized without error - NaiveDateTime::MIN, - NaiveDateTime::MIN.timestamp_millis().to_be_bytes(), + DateTime::::MIN_UTC, + DateTime::::MIN_UTC.timestamp_millis().to_be_bytes(), ), ( // UNIX epoch baseline - NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), + DateTime::from_timestamp(0, 0).unwrap(), 0i64.to_be_bytes(), ), ( // One second since UNIX epoch - NaiveDateTime::from_timestamp_opt(1, 0).unwrap(), + DateTime::from_timestamp(1, 0).unwrap(), 1000i64.to_be_bytes(), ), ( // 1 nanosecond since UNIX epoch, lost during serialization - NaiveDateTime::from_timestamp_opt(0, 1).unwrap(), + DateTime::from_timestamp(0, 1).unwrap(), 0i64.to_be_bytes(), ), ( // 1 millisecond since UNIX epoch - NaiveDateTime::from_timestamp_opt(0, 1_000_000).unwrap(), + DateTime::from_timestamp(0, 1_000_000).unwrap(), 1i64.to_be_bytes(), ), ( // 2 days before UNIX epoch - NaiveDateTime::from_timestamp_opt(-2 * 24 * 60 * 60, 0).unwrap(), + DateTime::from_timestamp(-2 * 24 * 60 * 60, 0).unwrap(), (-2 * 24i64 * 60 * 60 * 1000).to_be_bytes(), ), ]; - for (datetime, expected) in test_cases { - let test_datetime = datetime.and_utc(); + for (test_datetime, expected) in test_cases { let bytes: Vec = serialized(test_datetime, ColumnType::Timestamp); let mut expected_bytes: Vec = vec![0, 0, 0, 8]; diff --git a/scylla/Cargo.toml b/scylla/Cargo.toml index 665679c8e7..94c1047474 100644 --- a/scylla/Cargo.toml +++ b/scylla/Cargo.toml @@ -39,7 +39,7 @@ rand = "0.8.3" thiserror = "1.0" itertools = "0.11.0" tracing = "0.1.36" -chrono = { version = "0.4.20", default-features = false, features = ["clock"] } +chrono = { version = "0.4.33", default-features = false, features = ["clock"] } openssl = { version = "0.10.32", optional = true } tokio-openssl = { version = "0.6.1", optional = true } arc-swap = "1.3.0" diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 4dda187328..34fff67a67 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -861,10 +861,7 @@ async fn test_date_time() { let session = init_test("chrono_datetime_tests", "timestamp").await; let tests = [ - ( - "0", - NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc(), - ), + ("0", DateTime::from_timestamp(0, 0).unwrap()), ( "2001-02-03T04:05:06.789+0000", NaiveDateTime::new( diff --git a/scylla/src/utils/pretty.rs b/scylla/src/utils/pretty.rs index 5040ddb507..85f29eaa40 100644 --- a/scylla/src/utils/pretty.rs +++ b/scylla/src/utils/pretty.rs @@ -66,7 +66,12 @@ where )?, CqlValue::Counter(c) => write!(f, "{}", c.0)?, CqlValue::Date(CqlDate(d)) => { - let days_since_epoch = chrono::Duration::days(*d as i64 - (1 << 31)); + // This is basically a copy of the code used in `impl TryInto 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 + let days_since_epoch = chrono::Duration::try_days(*d as i64 - (1 << 31)).unwrap(); // TODO: chrono::NaiveDate does not handle the whole range // supported by the `date` datatype