This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1bf026b3f9e Fixed timestamp comparision bug in s3hook 
_sync_to_local_dir_if_changed method (#60299)
1bf026b3f9e is described below

commit 1bf026b3f9e1f34df8382cf7747b21f5712adf33
Author: Justin Pakzad <[email protected]>
AuthorDate: Thu Jan 8 20:24:43 2026 -0500

    Fixed timestamp comparision bug in s3hook _sync_to_local_dir_if_changed 
method (#60299)
---
 .../amazon/src/airflow/providers/amazon/aws/hooks/s3.py |  2 +-
 providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/providers/amazon/src/airflow/providers/amazon/aws/hooks/s3.py 
b/providers/amazon/src/airflow/providers/amazon/aws/hooks/s3.py
index df6bad2d00b..f24cebc8be6 100644
--- a/providers/amazon/src/airflow/providers/amazon/aws/hooks/s3.py
+++ b/providers/amazon/src/airflow/providers/amazon/aws/hooks/s3.py
@@ -1757,7 +1757,7 @@ class S3Hook(AwsBaseHook):
                 )
 
             s3_last_modified = s3_object.last_modified
-            if local_stats.st_mtime < s3_last_modified.microsecond:
+            if local_stats.st_mtime < s3_last_modified.timestamp():
                 should_download = True
                 download_msg = f"S3 object last modified 
({s3_last_modified.microsecond}) and local file last modified 
({local_stats.st_mtime}) differ."
 
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py 
b/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
index 265d4350bc0..4b6dae9c206 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
@@ -1840,6 +1840,23 @@ class TestAwsS3Hook:
         assert "S3 object size" in logs_string
         assert "differ. Downloaded dag_03.py to" in logs_string
 
+        local_file_same_size = Path(sync_local_dir).joinpath("dag_04.py")
+        local_file_same_size.write_text("same size")
+
+        s3_client.put_object(Bucket=s3_bucket, Key="dag_04.py", Body=b"same 
size")
+
+        prev_ts = local_file_same_size.stat().st_mtime - 5
+        os.utime(local_file_same_size, (prev_ts, prev_ts))
+
+        hook.log.debug = MagicMock()
+        hook.sync_to_local_dir(
+            bucket_name=s3_bucket, local_dir=sync_local_dir, s3_prefix="", 
delete_stale=True
+        )
+        logs_string = get_logs_string(hook.log.debug.call_args_list)
+        assert "S3 object last modified" in logs_string
+        assert "local file last modified" in logs_string
+        assert "differ. Downloaded dag_04.py to" in logs_string
+
 
 @pytest.mark.parametrize(
     ("key_kind", "has_conn", "has_bucket", "precedence", "expected"),

Reply via email to