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

DateTime field: allow timestamp 0 #2264

Merged
merged 3 commits into from
May 1, 2024
Merged

DateTime field: allow timestamp 0 #2264

merged 3 commits into from
May 1, 2024

Conversation

lafrech
Copy link
Member

@lafrech lafrech commented Apr 30, 2024

Fixes #2133.

@lafrech lafrech requested review from sloria and deckar01 April 30, 2024 09:27
Copy link
Member

@sloria sloria left a comment

Choose a reason for hiding this comment

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

Just a tiny suggestion. Good to merge and release

@@ -576,7 +577,7 @@ def test_timestamp_field_deserialization(self, fmt, value, expected):
@pytest.mark.parametrize("fmt", ["timestamp", "timestamp_ms"])
@pytest.mark.parametrize(
"in_value",
["", "!@#", 0, -1, dt.datetime(2013, 11, 10, 1, 23, 45)],
["", "!@#", -1, dt.datetime(2013, 11, 10, 1, 23, 45)],
Copy link
Member

Choose a reason for hiding this comment

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

Nit: might be worth testing None here

Copy link
Member Author

Choose a reason for hiding this comment

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

None fails validation before reaching _deserialize.

ValidationError: Field may not be null.

@@ -422,6 +422,7 @@ def test_field_toggle_show_invalid_value_in_error_message(self):
[
"not-a-datetime",
42,
0,
Copy link
Member

Choose a reason for hiding this comment

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

thought(non-blocking): I believe this will also make False a valid value which isn't totally intuitive. But I'm not sure there's a way around that

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a condition to reject boolean inputs, copied from numeric fields above.

Copy link
Member

@deckar01 deckar01 May 1, 2024

Choose a reason for hiding this comment

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

I would be tempted to inherit Float to match datetime.fromtimestamp()'s type signature and avoid duplicating that logic. That would also allow removing value = float(value) from utils.from_timestamp() which is equally guilty for the unexpected bool to int promotion.

Copy link
Member

Choose a reason for hiding this comment

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

On second thought inheritance wouldn't really work with the other date formats.

I would push this logic down to utils.from_timestamp() since all of the other date time utils.from_* properly error on bools already.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. I added your commit to the PR.

@lafrech lafrech merged commit 03f56a4 into dev May 1, 2024
9 checks passed
@lafrech lafrech deleted the allow_timestamp_0 branch May 1, 2024 21:04
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.

timestamp 0 is not valid for DateTime('timestamp')
3 participants