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

fix: handle null values in array query parameters #426

Merged
merged 1 commit into from Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/bigquery/_helpers.py
Expand Up @@ -40,7 +40,7 @@

def _not_null(value, field):
"""Check whether 'value' should be coerced to 'field' type."""
return value is not None or field.mode != "NULLABLE"
return value is not None or (field is not None and field.mode != "NULLABLE")


def _int_from_json(value, field):
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_query.py
Expand Up @@ -383,6 +383,16 @@ def test_from_api_repr_wo_values(self):
self.assertEqual(param.array_type, "INT64")
self.assertEqual(param.values, [])

def test_from_api_repr_w_none_values(self):
RESOURCE = {
"parameterType": {"type": "ARRAY", "arrayType": {"type": "INT64"}},
"parameterValue": {"arrayValues": [{"value": "1"}, {"value": None}]},
}
klass = self._get_target_class()
param = klass.from_api_repr(RESOURCE)
self.assertEqual(param.array_type, "INT64")
self.assertEqual(param.values, [1, None])

def test_from_api_repr_w_struct_type(self):
from google.cloud.bigquery.query import StructQueryParameter

Expand Down