Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQueryHook Requires Optional Field When Parsing Results Schema #26785

Closed
2 tasks done
patricker opened this issue Sep 29, 2022 · 0 comments · Fixed by #26786
Closed
2 tasks done

BigQueryHook Requires Optional Field When Parsing Results Schema #26785

patricker opened this issue Sep 29, 2022 · 0 comments · Fixed by #26786
Labels
area:providers kind:bug This is a clearly a bug

Comments

@patricker
Copy link
Contributor

Apache Airflow Provider(s)

google

Versions of Apache Airflow Providers

apache-airflow-providers-google 8.3.0

Apache Airflow version

2.3.4

Operating System

OSX

Deployment

Virtualenv installation

Deployment details

No response

What happened

When querying BigQuery using the BigQueryHook, sometimes the following error is returned:

[2022-09-29, 19:04:57 UTC] {{taskinstance.py:1902}} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/operators/python.py", line 171, in execute
    return_value = self.execute_callable()
  File "/usr/local/lib/python3.9/site-packages/airflow/operators/python.py", line 189, in execute_callable
    return self.python_callable(*self.op_args, **self.op_kwargs)
  File "/usr/src/app/dags/test.py", line 23, in curried_bigquery
    cursor.execute(UPDATE_HIGHWATER_MARK_QUERY)
  File "/usr/local/lib/python3.9/site-packages/airflow/providers/google/cloud/hooks/bigquery.py", line 2700, in execute
    self.description = _format_schema_for_description(query_results["schema"])
  File "/usr/local/lib/python3.9/site-packages/airflow/providers/google/cloud/hooks/bigquery.py", line 3009, in _format_schema_for_description
    field["mode"] == "NULLABLE",
KeyError: 'mode'

What you think should happen instead

The schema should be returned without error.

How to reproduce

No response

Anything else

According to the official docs, only name and type are required to be present. mode is listed as optional.
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableFieldSchema

The code currently expects mode to be present.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers kind:bug This is a clearly a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant