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

Resolve SOURCE_DATE_EPOCH=0 bug. #3795

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Resolve SOURCE_DATE_EPOCH=0 bug. #3795

merged 2 commits into from
Aug 28, 2024

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Aug 1, 2024

Closes #3794

Not clear to me if...

  • There may also be a timezone issue here leading to the negative value.

And furthermore...

  • Non-integer values will still raise an exception here.

But this does at least resolve the immediate issue.

Thanks to @vedranmiletic for raising the issue and @pawamoy for the confimation.

Not clear to me if...

* There may also be a timezone issue here leading to the negative value.

And furthermore...

* Non-integer values will still raise an exception here.

But this does at least resolve the immediate issue.
@tomchristie tomchristie added the Bug label Aug 1, 2024
Copy link
Sponsor Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix @tomchristie. Just wondering what the issue exactly was.

@@ -56,7 +56,7 @@ def get_build_timestamp(*, pages: Collection[Page] | None = None) -> int:
dt = datetime.fromisoformat(date_string)
else:
dt = get_build_datetime()
return int(dt.timestamp())
return max(int(dt.timestamp()), 0)
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I'm not sure to understand the fix (but believe you that it actually fixes the issue). Is it a timezone-aware/naive issue? I gather int(dt.timestamp()) would return a negative integer when there are no pages and SOURCE_DATE_EPOCH=0? But why 🤔?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Should we add an actual test by the way? To prevent any regression.

@@ -53,7 +53,7 @@ def get_build_timestamp(*, pages: Collection[Page] | None = None) -> int:
if pages:
# Lexicographic comparison is OK for ISO date.
date_string = max(p.update_date for p in pages)
dt = datetime.fromisoformat(date_string)
dt = datetime.fromisoformat(date_string).replace(tzinfo=timezone.utc)
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that we're using utc timezone datetimes everywhere, except here.
The robust fix is that we update this naive timezone into a utc based timezone.

@tomchristie tomchristie merged commit 0b22a52 into master Aug 28, 2024
34 checks passed
@tomchristie tomchristie deleted the tomchristie-patch-1 branch August 28, 2024 13:08
@vedranmiletic
Copy link
Contributor

Thanks!

@tomchristie tomchristie mentioned this pull request Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build with SOURCE_DATE_EPOCH=0 fails
3 participants