Closed
Description
Environment details
- OS type and version: macOS Big Sur 11.6.1
- Python version:
3.9.7
- pip version:
21.3.1
google-cloud-bigquery
version:2.29.0
Description
Prior versions of google-cloud-bigquery
(2.3.1
) allowed SchemaField
instantiation based on an existing SchemaField
__repr__
.
Use Case
- System generates list of
SchemaField
and passes it through a Jinja template as part of building hundreds of Airflow DAGs. - Jinja prints
__repr__
from theSchemaField
into the templated.py
. - Airflow picks up the
.py
files and executes them. - Execution results in the below error.
Code example
In version 2.3.1
from google.cloud.bigquery import SchemaField
from google.cloud import bigquery
bigquery.__version__
'2.3.1'
# This works
field = SchemaField('name', 'STRING', 'REQUIRED', 'Name')
field.__repr__()
"SchemaField('name', 'STRING', 'REQUIRED', 'Name', (), ())"
# Jinja prints ^^ to a .py file
# When the file is executed the SchemaField is created without issue
Version 2.29.0
:
from google.cloud.bigquery import SchemaField
from google.cloud import bigquery
bigquery.__version__
'2.29.0'
# This raises an error for the tuple in the last field
field = SchemaField('name', 'STRING', 'REQUIRED', 'Name')
field.__repr__()
"SchemaField('name', 'STRING', 'REQUIRED', 'Name', (), ())"
# Jinja prints ^^ to a .py file
# When the file is executed, an error is raised:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wes.roach/.pyenv/versions/upgr-dbt/lib/python3.9/site-packages/google/cloud/bigquery/schema.py", line 125, in __init__
policy_tags.to_api_repr() if policy_tags is not None else None
AttributeError: 'tuple' object has no attribute 'to_api_repr'
Setting the policy_tags
to None
still results in ()
.
field = SchemaField('name', 'STRING', 'REQUIRED', 'Name', (), None)
field.__repr__()
"SchemaField('name', 'STRING', 'REQUIRED', 'Name', (), ())"