Skip to content

Commit 78fde4a

Browse files
fix: handle null values in array query parameters (#426)
1 parent 763fb2c commit 78fde4a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

google/cloud/bigquery/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

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

4545

4646
def _int_from_json(value, field):

tests/unit/test_query.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ def test_from_api_repr_wo_values(self):
383383
self.assertEqual(param.array_type, "INT64")
384384
self.assertEqual(param.values, [])
385385

386+
def test_from_api_repr_w_none_values(self):
387+
RESOURCE = {
388+
"parameterType": {"type": "ARRAY", "arrayType": {"type": "INT64"}},
389+
"parameterValue": {"arrayValues": [{"value": "1"}, {"value": None}]},
390+
}
391+
klass = self._get_target_class()
392+
param = klass.from_api_repr(RESOURCE)
393+
self.assertEqual(param.array_type, "INT64")
394+
self.assertEqual(param.values, [1, None])
395+
386396
def test_from_api_repr_w_struct_type(self):
387397
from google.cloud.bigquery.query import StructQueryParameter
388398

0 commit comments

Comments
 (0)