Skip to content

Commit 65eec54

Browse files
authored
Block calling 'DocumentRef.get()' with a single string. (googleapis#6270)
Closes googleapis#6203.
1 parent c0c7ed6 commit 65eec54

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

firestore/google/cloud/firestore_v1beta1/document.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
"""Classes for representing documents for the Google Cloud Firestore API."""
1616

17-
1817
import copy
1918

19+
import six
20+
2021
from google.cloud.firestore_v1beta1 import _helpers
2122

2223

@@ -418,6 +419,9 @@ def get(self, field_paths=None, transaction=None):
418419
`update_time`, and `create_time` attributes will all be
419420
`None` and `exists` will be `False`.
420421
"""
422+
if isinstance(field_paths, six.string_types):
423+
raise ValueError(
424+
"'field_paths' must be a sequence of paths, not a string.")
421425
snapshot_generator = self._client.get_all(
422426
[self], field_paths=field_paths, transaction=transaction)
423427
return _consume_single_get(snapshot_generator)

firestore/tests/unit/test_document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ def test_delete_with_option(self):
449449
)
450450
self._delete_helper(last_update_time=timestamp_pb)
451451

452+
def test_get_w_single_field_path(self):
453+
client = mock.Mock(spec=[])
454+
455+
document = self._make_one('yellow', 'mellow', client=client)
456+
with self.assertRaises(ValueError):
457+
document.get('foo')
458+
452459
def test_get_success(self):
453460
# Create a minimal fake client with a dummy response.
454461
response_iterator = iter([mock.sentinel.snapshot])

0 commit comments

Comments
 (0)