Repository navigation
BigQuery: query_parameters fails if empty array is bound as parameter #7309
Copy link
Copy link
Closed
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
OS Type & Version: Ubuntu 18.10 x64
Python version: Python 3.7.1
Packges: latest up to this date:
(...)
google-cloud-bigquery==1.9.0
(...)
Steps to reproduce
- Create a query, bind empty array as parameter
- Execute it
- Call query_parameters
Code example
from google.cloud import bigquery
client = bigquery.Client()
job = client.query(
"SELECT ARRAY_LENGTH(@empty_array)",
job_config=bigquery.QueryJobConfig(
query_parameters=[
bigquery.ArrayQueryParameter('empty_array', 'INT64', [])
]
)
)
result = list(job.result())
query_parameters = job.query_parameters
Stack trace
Traceback (most recent call last):
File "test.py", line 13, in <module>
query_parameters = job.query_parameters()
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 2373, in query_parameters
return self._configuration.query_parameters
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 2115, in query_parameters
return _from_api_repr_query_parameters(prop)
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 1908, in _from_api_repr_query_parameters
return [_query_param_from_api_repr(mapping) for mapping in resource]
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 1908, in <listcomp>
return [_query_param_from_api_repr(mapping) for mapping in resource]
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/query.py", line 623, in _query_param_from_api_repr
return klass.from_api_repr(resource)
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/query.py", line 252, in from_api_repr
return cls._from_api_repr_scalar(resource)
File "python-bigquery-bug/venv/lib/python3.7/site-packages/google/cloud/bigquery/query.py", line 233, in _from_api_repr_scalar
values = [value["value"] for value in resource["parameterValue"]["arrayValues"]]
KeyError: 'parameterValue'
from_api_repr in ArrayQueryParameter is called with resource = {'name': 'empty_array', 'parameterType': {'arrayType': {'type': 'INT64'}, 'type': 'ARRAY'}}
For empty array this value does not contain parameterValue which leads to KeyError
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
tseaver commentedon Feb 12, 2019
@peku33 Thank you for the report!
Harden 'ArrayQueryParameter.from_api_repr' against missing 'parameter…
peku33 commentedon Aug 12, 2019
@tseaver This is still an issue on 1.18.0 if bound parameter is
None.tseaver commentedon Aug 12, 2019
@peku33
Can you supply an example showing how to trigger that case?
peku33 commentedon Aug 12, 2019
raises:
peku33 commentedon Aug 13, 2019
@tseaver Is it enough to report the issue or should I open new request?
tseaver commentedon Aug 13, 2019
@peku33 The exceptoin you report is really a slightly different issue: please open it, and reference this one in the description.