Skip to content

Commit 81778c8

Browse files
fa-assistanttlm365TIHanfindepi
committed
COPYBARA PUBLIC PR: #145 (#3829)
* COPYBARA PUBLIC PR: https://github.com/dbt-labs/dbt-fusion/145 Make modules.pytz.timezone compatible with dbt-core GitOrigin-RevId: 7fda2a1 * Fixing build * Added changelog. Trying to fix build. * Reset Cargo.lock and update it again * Declare chrono-tz case-insensitive feature workspace-wide chrono-tz & chrono-tz-build makes incorrect assumptions about how cargo works, leading to compile time failures. This can happen when something enables chrono-tz-build crate > case-insensitive feature, without enabling chrono-tz crate > case-insensitive feature. * Added changelog * Added changelog --------- Co-authored-by: Tai Le Manh <[email protected]> Co-authored-by: TIHan <[email protected]> Co-authored-by: Piotr Findeisen <[email protected]> GitOrigin-RevId: 20df6e9ab7ec01ec62a9ff52db45aafc3d22bc33
1 parent c70a4b3 commit 81778c8

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixes
2+
body: Make modules.pytz.timezone compatible with dbt-core by tlm365.
3+
time: 2025-06-18T09:27:35.642874-07:00

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ base64 = "0.22.1"
301301
bigdecimal = "0.4.7"
302302
blake3 = "1.5.0"
303303
chrono = { version = "0.4.31", features = ["std", "clock", "serde"] }
304-
chrono-tz = { version = "0.10.1" }
304+
chrono-tz = { version = "0.10.1", features = ["case-insensitive"] }
305305
clap = { version = "4.4.4", features = ["derive"] }
306306
counter = "0.6.0"
307307
dashmap = "6.1.0"

crates/dbt-jinja/minijinja-contrib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ unicode_wordwrap = [
3131

3232
[dependencies]
3333
chrono = { version = "0.4.26", features = ["serde"] }
34-
chrono-tz = { version = "0.10.1" }
34+
chrono-tz = { workspace = true }
3535
fancy-regex = { workspace = true }
3636
iana-time-zone = { workspace = true }
3737
minijinja = { workspace = true }

crates/dbt-jinja/minijinja-contrib/src/modules/pytz.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use chrono_tz::Tz;
33
use minijinja::{Error, ErrorKind, Value};
44
use std::collections::BTreeMap;
55
use std::fmt;
6-
use std::str::FromStr;
76
use std::sync::Arc;
87

98
/// A Python-like "pytz" timezone object that wraps a `chrono_tz::Tz`.
@@ -81,7 +80,7 @@ fn timezone(args: &[Value]) -> Result<Value, Error> {
8180
})?;
8281

8382
// Try to parse it as a Chrono Tz.
84-
match Tz::from_str(tz_name) {
83+
match Tz::from_str_insensitive(tz_name) {
8584
Ok(tz) => Ok(Value::from_object(PytzTimezone::new(tz))),
8685
Err(_) => Err(Error::new(
8786
ErrorKind::InvalidArgument,
@@ -116,3 +115,42 @@ impl minijinja::value::Object for PytzTimezone {
116115
write!(f, "{}", self.tz)
117116
}
118117
}
118+
119+
#[cfg(test)]
120+
mod tests {
121+
use crate::modules::pytz::{timezone, PytzTimezone};
122+
use chrono_tz::Tz;
123+
use minijinja::Value;
124+
125+
#[test]
126+
fn test_valid_timezone_utc() {
127+
let args = vec![Value::from("UTC")];
128+
let result = timezone(&args);
129+
assert!(result.is_ok());
130+
131+
let actual = result.unwrap();
132+
let expected = Value::from_object(PytzTimezone::new(chrono_tz::UTC));
133+
assert_eq!(actual, expected);
134+
}
135+
136+
#[test]
137+
fn test_valid_timezone_case_insensitive() {
138+
let args = vec![Value::from("asia/ho_chi_minh")];
139+
let result = timezone(&args);
140+
assert!(result.is_ok());
141+
142+
let actual = result.unwrap();
143+
let expected = Value::from_object(PytzTimezone::new(Tz::Asia__Ho_Chi_Minh));
144+
assert_eq!(actual, expected);
145+
}
146+
147+
#[test]
148+
fn test_invalid_timezone() {
149+
let args = vec![Value::from("Invalid/Zone")];
150+
let result = timezone(&args);
151+
assert!(result.is_err());
152+
153+
let err = result.unwrap_err();
154+
assert!(err.to_string().contains("Invalid timezone name"));
155+
}
156+
}

0 commit comments

Comments
 (0)