Skip to content

Commit 710141e

Browse files
committed
Address review feedback on S3CopyPrefixOperator
Chain RuntimeError from the original exception to preserve the traceback. Verify the succeeding object is attempted when continue_on_failure=True.
1 parent 54c2f90 commit 710141e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

  • providers/amazon
    • src/airflow/providers/amazon/aws/operators
    • tests/unit/amazon/aws/operators

providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def execute(self, context: Context):
506506
self.log.error("Failed to copy %s: %s", source_key, e)
507507
failed_object_count += 1
508508
else:
509-
raise RuntimeError(f"Failed to copy {source_key}: {e}")
509+
raise RuntimeError(f"Failed to copy {source_key}: {e}") from e
510510

511511
self.log.info("Successfully copied %s object(s)", copied_object_count)
512512

providers/amazon/tests/unit/amazon/aws/operators/test_s3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,13 @@ def mock_copy_object(*args, **kwargs):
860860
raise Exception("Copy failed for file1")
861861
return None
862862

863-
with mock.patch.object(op.hook, "copy_object", side_effect=mock_copy_object):
863+
with mock.patch.object(op.hook, "copy_object", side_effect=mock_copy_object) as mock_copy:
864864
with pytest.raises(RuntimeError, match=r"Failed to copy 1 object\(s\)"):
865865
op.execute(None)
866866

867+
attempted_keys = [call.kwargs["source_bucket_key"] for call in mock_copy.call_args_list]
868+
assert f"{self.source_prefix}file2.txt" in attempted_keys
869+
867870
@pytest.mark.parametrize(
868871
"op_kwargs",
869872
[

0 commit comments

Comments
 (0)