Skip to content

SchemaField cannot initialize from __repr__ #1041

Closed
@WesRoach

Description

@WesRoach

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

  1. System generates list of SchemaField and passes it through a Jinja template as part of building hundreds of Airflow DAGs.
  2. Jinja prints __repr__ from the SchemaField into the templated .py.
  3. Airflow picks up the .py files and executes them.
  4. 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', (), ())"

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions