Skip to content

When the field of providers-google is False, the value is incorrect #47053

@snc-lin

Description

@snc-lin

Apache Airflow Provider(s)

google

Versions of Apache Airflow Providers

12.0.0

Apache Airflow version

2.10.5

Operating System

Ubuntu 22.04.5 LTS

Deployment

Docker-Compose

Deployment details

No response

What happened

If the value of the GoogleBaseHook field is False, it always returns the default value.
Specifically, even if use_legacy_sql in BigQueryHook is set to False, it still returns the default value of True.

What you think should happen instead

If use_legacy_sql in BigQueryHook is set to False, the use_legacy_sql parameter should also be False.

How to reproduce

Create a BigQuery connection with use_legacy_sql set to False (for example, bigquery_default). And, run the following code.

from airflow.decorators import dag, task
from airflow.providers.google.cloud.hooks.bigquery import BigQueryHook

@dag()
def bigquery_dag():
    @task()
    def debug():
        hook = BigQueryHook.get_hook("bigquery_default")
        print(hook.use_legacy_sql)

    debug()

bigquery_dag()

Anything else

I think I need to fix the code(https://github.com/apache/airflow/blob/providers-google/12.0.0/providers/src/airflow/providers/google/common/hooks/base_google.py#L412) as follows.

before:
return hasattr(self, "extras") and get_field(self.extras, f) or default

after:

if hasattr(self, "extras") and get_field(self.extras, f) is not None:
    return get_field(self.extras, f)
else:
    default

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions