Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82170b5

Browse filesBrowse files
o-aleksasthamohtapartheaIlyaFaer
authored
fix: if JsonObject serialized to None then return null_value instead of string_value (#771)
* fix: if JsonObject serialized to None then return `null_value` instead of `string_value` Co-authored-by: Astha Mohta <35952883+asthamohta@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com> Co-authored-by: Ilya Gurov <gurovilya9@gmail.com>
1 parent def00a8 commit 82170b5
Copy full SHA for 82170b5

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed

‎google/cloud/spanner_v1/_helpers.py

Copy file name to clipboardExpand all lines: google/cloud/spanner_v1/_helpers.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ def _make_value_pb(value):
165165
_assert_numeric_precision_and_scale(value)
166166
return Value(string_value=str(value))
167167
if isinstance(value, JsonObject):
168-
return Value(string_value=value.serialize())
168+
value = value.serialize()
169+
if value is None:
170+
return Value(null_value="NULL_VALUE")
171+
else:
172+
return Value(string_value=value)
169173

170174
raise ValueError("Unknown type: %s" % (value,))
171175

‎tests/unit/test__helpers.py

Copy file name to clipboardExpand all lines: tests/unit/test__helpers.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ def test_w_json(self):
306306
self.assertIsInstance(value_pb, Value)
307307
self.assertEqual(value_pb.string_value, value)
308308

309+
def test_w_json_None(self):
310+
from google.cloud.spanner_v1 import JsonObject
311+
312+
value = JsonObject(None)
313+
value_pb = self._callFUT(value)
314+
self.assertTrue(value_pb.HasField("null_value"))
315+
309316

310317
class Test_make_list_value_pb(unittest.TestCase):
311318
def _callFUT(self, *args, **kw):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.