Skip to content

Implicit exception in GCSToLocalFilesystemOperator when reading non-existing files #42439

@shahar1

Description

@shahar1

Apache Airflow Provider(s)

google

Versions of Apache Airflow Providers

10.15.0

Apache Airflow version

2.6.3

Operating System

Debian

Deployment

Google Cloud Composer

Deployment details

No response

What happened

When using GCSToLocalFilesystemOperator on a non-existing object, the resulted exception is regarding a NoneType object with no size attribute - which is True, but it would be better to raise an exception that the file simply does not exist.

What you think should happen instead

No response

How to reproduce

Use the GCSToLocalFilesystemOperator with a non-existing OBJECT_NAME

    gcs_to_fs = GCSToLocalFilesystemOperator(
        task_id="gcs_to_fs",
        bucket=BUCKET,  # <- exists
        object_name=OBJECT_NAME, # <- does not exist
    )

You'll get an exception similar to this:

Traceback (most recent call last):
  File "/opt/python3.11/lib/python3.11/site-packages/airflow/providers/google/cloud/transfers/gcs_to_local.py", line 118, in execute
    file_size = hook.get_size(bucket_name=self.bucket, object_name=self.object_name)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python3.11/lib/python3.11/site-packages/airflow/providers/google/cloud/hooks/gcs.py", line 968, in get_size
    blob_size = blob.size
                ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'size'

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions