Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions google/cloud/firestore_v1/async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ async def add(
write_result = await document_ref.create(document_data, **kwargs)
return write_result.update_time, document_ref

def document(
self, document_id: str = None
) -> async_document.AsyncDocumentReference:
"""Create a sub-document underneath the current collection.

Args:
document_id (Optional[str]): The document identifier
within the current collection. If not provided, will default
to a random 20 character string composed of digits,
uppercase and lowercase and letters.

Returns:
:class:`~google.cloud.firestore_v1.document.async_document.AsyncDocumentReference`:
The child document.
"""
return super(AsyncCollectionReference, self).document(document_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's unfortunate that we still use the Python 2 syntax here, though I see that's the pattern across the library and you were just following it. Nothing to do here except collectively shrug our shoulders.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are welcome to go through and refactor this. This is less a choice and more a fact that this library evolved from Py2/3 compliant code and we didn't refactor more than necessary to use new features really (AsyncIO, f strings, etc)


async def list_documents(
self,
page_size: int = None,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/v1/test_async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_query_method_matching(self):
# ``AsyncCollectionReference``.
self.assertLessEqual(query_methods, collection_methods)

def test_document_name_default(self):
client = _make_client()
document = client.collection("test").document()
# name is random, but assert it is not None
self.assertTrue(document.id is not None)

def test_constructor(self):
collection_id1 = "rooms"
document_id = "roomA"
Expand Down