@@ -90,6 +90,8 @@ class GCSToGCSOperator(BaseOperator):
90
90
If set as a sequence, the identities from the list must grant
91
91
Service Account Token Creator IAM role to the directly preceding identity, with first
92
92
account from the list granting this role to the originating account (templated).
93
+ :param source_object_required: Whether you want to raise an exception when the source object
94
+ doesn't exist. It doesn't have any effect when the source objects are folders or patterns.
93
95
94
96
:Example:
95
97
@@ -190,6 +192,7 @@ def __init__(
190
192
maximum_modified_time = None ,
191
193
is_older_than = None ,
192
194
impersonation_chain : Optional [Union [str , Sequence [str ]]] = None ,
195
+ source_object_required = False ,
193
196
** kwargs ,
194
197
):
195
198
super ().__init__ (** kwargs )
@@ -216,6 +219,7 @@ def __init__(
216
219
self .maximum_modified_time = maximum_modified_time
217
220
self .is_older_than = is_older_than
218
221
self .impersonation_chain = impersonation_chain
222
+ self .source_object_required = source_object_required
219
223
220
224
def execute (self , context : 'Context' ):
221
225
@@ -313,6 +317,11 @@ def _copy_source_without_wildcard(self, hook, prefix):
313
317
self ._copy_single_object (
314
318
hook = hook , source_object = prefix , destination_object = self .destination_object
315
319
)
320
+ elif self .source_object_required :
321
+ msg = f"{ prefix } does not exist in bucket { self .source_bucket } "
322
+ self .log .warning (msg )
323
+ raise AirflowException (msg )
324
+
316
325
for source_obj in objects :
317
326
if self .destination_object is None :
318
327
destination_object = source_obj
0 commit comments