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
verification: add test_verify_tz_aware #10229
Conversation
Signed-off-by: William Woodruff <william@trailofbits.com>
CC @reaperhulk |
Thinking about this a bit: the underlying (already identified cause) is this implementation of pub(crate) fn py_to_datetime(
py: pyo3::Python<'_>,
val: &pyo3::PyAny,
) -> pyo3::PyResult<asn1::DateTime> {
Ok(asn1::DateTime::new(
val.getattr(pyo3::intern!(py, "year"))?.extract()?,
val.getattr(pyo3::intern!(py, "month"))?.extract()?,
val.getattr(pyo3::intern!(py, "day"))?.extract()?,
val.getattr(pyo3::intern!(py, "hour"))?.extract()?,
val.getattr(pyo3::intern!(py, "minute"))?.extract()?,
val.getattr(pyo3::intern!(py, "second"))?.extract()?,
)
.unwrap())
} When a One potential fix here is to check the While more correct, this is technically a behavioral change as well 🙂 |
I think my intuition is that we could just always call astimezone(utc) and then get the attributes |
I can do this, but it'll have a slightly weird effect on existing naive datetimes:
In other words, naive datetimes will be treated as local time, rather than the current assumption that they're already UTC. But if that's okay, I can go forward with calling |
I don't think it would be a good idea to have our existing code start treating naïve datetimes as local. We consider (and have documented) naïve datetimes to be UTC all over our APIs. @woodruffw is your statement about the behavior change for your proposed approach because it previously would just ignore the TZ and now it will not, which means people who are relying on (undocumented and incorrect) behavior may experience breakage? 😄 If so, I agree it is a behavior change, but a worthwhile one. |
I think what we want is:
|
Yep, exactly that 🙂
Sounds good -- in that case I think we do need to sniff I'll make those changes now! |
Great. |
Since |
It might be possible to remove that with this? |
Yeah, I'll investigate. |
Signed-off-by: William Woodruff <william@trailofbits.com>
I've parameterized the test to add positive and negative cases, and confirmed that they work as expected (and that both fail with the old codepath, as expected). I'll look into |
Removing
These seem moderately annoying to fix, since they happen in Python before we perform our (new) timezone normalization. So maybe it makes sense to leave |
(CI failure looks spurious) |
Yes, pypy is known flaky right now 😭 |
Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
Sigh, coverage. Fixing. |
Signed-off-by: William Woodruff <william@trailofbits.com>
This adds a TZ awareness test, which is currently failing. I'll use this PR to investigate a fix as well.