Skip to content

Commit ee6a1c2

Browse files
authored
fix: update type hint for async_collection.document() to AsyncDocumen… (#370)
…tReference Fixes #369 🦕
1 parent 77e6ced commit ee6a1c2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

google/cloud/firestore_v1/async_collection.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ async def add(
112112
write_result = await document_ref.create(document_data, **kwargs)
113113
return write_result.update_time, document_ref
114114

115+
def document(
116+
self, document_id: str = None
117+
) -> async_document.AsyncDocumentReference:
118+
"""Create a sub-document underneath the current collection.
119+
120+
Args:
121+
document_id (Optional[str]): The document identifier
122+
within the current collection. If not provided, will default
123+
to a random 20 character string composed of digits,
124+
uppercase and lowercase and letters.
125+
126+
Returns:
127+
:class:`~google.cloud.firestore_v1.document.async_document.AsyncDocumentReference`:
128+
The child document.
129+
"""
130+
return super(AsyncCollectionReference, self).document(document_id)
131+
115132
async def list_documents(
116133
self,
117134
page_size: int = None,

tests/unit/v1/test_async_collection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def test_query_method_matching(self):
5757
# ``AsyncCollectionReference``.
5858
self.assertLessEqual(query_methods, collection_methods)
5959

60+
def test_document_name_default(self):
61+
client = _make_client()
62+
document = client.collection("test").document()
63+
# name is random, but assert it is not None
64+
self.assertTrue(document.id is not None)
65+
6066
def test_constructor(self):
6167
collection_id1 = "rooms"
6268
document_id = "roomA"

0 commit comments

Comments
 (0)