@@ -90,6 +90,8 @@ class GCSToGCSOperator(BaseOperator):
9090 If set as a sequence, the identities from the list must grant
9191 Service Account Token Creator IAM role to the directly preceding identity, with first
9292 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.
9395
9496 :Example:
9597
@@ -190,6 +192,7 @@ def __init__(
190192 maximum_modified_time = None ,
191193 is_older_than = None ,
192194 impersonation_chain : Optional [Union [str , Sequence [str ]]] = None ,
195+ source_object_required = False ,
193196 ** kwargs ,
194197 ):
195198 super ().__init__ (** kwargs )
@@ -216,6 +219,7 @@ def __init__(
216219 self .maximum_modified_time = maximum_modified_time
217220 self .is_older_than = is_older_than
218221 self .impersonation_chain = impersonation_chain
222+ self .source_object_required = source_object_required
219223
220224 def execute (self , context : 'Context' ):
221225
@@ -313,6 +317,11 @@ def _copy_source_without_wildcard(self, hook, prefix):
313317 self ._copy_single_object (
314318 hook = hook , source_object = prefix , destination_object = self .destination_object
315319 )
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+
316325 for source_obj in objects :
317326 if self .destination_object is None :
318327 destination_object = source_obj
0 commit comments