Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.
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
6 changes: 2 additions & 4 deletions google/cloud/firestore_v1/field_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
_ESCAPED_BACKTICK = _BACKSLASH + _BACKTICK

_SIMPLE_FIELD_NAME = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*$")
_LEADING_ALPHA_INVALID = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*[^_a-zA-Z0-9]")
_LEADING_ALPHA_INVALID = re.compile(r"^[_a-zA-Z][_a-zA-Z0-9]*[~*/\[\]]")
PATH_ELEMENT_TOKENS = [
("SIMPLE", r"[_a-zA-Z][_a-zA-Z0-9]*"), # unquoted elements
("QUOTED", r"`(?:\\`|[^`])*?`"), # quoted elements, unquoted
Expand Down Expand Up @@ -311,9 +311,7 @@ def from_string(cls, path_string: str):
raise ValueError("Empty element")
if _LEADING_ALPHA_INVALID.match(element):
raise ValueError(
"Non-alphanum char in element with leading alpha: {}".format(
element
)
"Invalid char in element with leading alpha: {}".format(element)
)
return FieldPath(*elements)

Expand Down
40 changes: 40 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,28 @@ def in_transaction(transaction):
assert inner_fn_ran is True


@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
def test_transaction_w_uuid(client, cleanup, database):
"""
https://github.com/googleapis/python-firestore/issues/1012
"""
collection_id = "uuid_collection" + UNIQUE_RESOURCE_ID
doc_ref = client.document(collection_id, "doc")
cleanup(doc_ref.delete)
key = "b7992822-eacb-40be-8af6-559b9e2fb0b7"
doc_ref.create({key: "I'm a UUID!"})

@firestore.transactional
def update_doc(tx, doc_ref, key, value):
tx.update(doc_ref, {key: value})

expected = "UPDATED VALUE"
update_doc(client.transaction(), doc_ref, key, expected)
# read updated doc
snapshot = doc_ref.get()
assert snapshot.to_dict()[key] == expected


@pytest.mark.skipif(
FIRESTORE_EMULATOR, reason="Query profile not supported in emulator."
)
Expand Down Expand Up @@ -3206,6 +3228,24 @@ def in_transaction(transaction):
assert inner_fn_ran is True


@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
def test_update_w_uuid(client, cleanup, database):
"""
https://github.com/googleapis/python-firestore/issues/1012
"""
collection_id = "uuid_collection" + UNIQUE_RESOURCE_ID
doc_ref = client.document(collection_id, "doc")
cleanup(doc_ref.delete)
key = "b7992822-eacb-40be-8af6-559b9e2fb0b7"
doc_ref.create({key: "I'm a UUID!"})

expected = "UPDATED VALUE"
doc_ref.update({key: expected})
# read updated doc
snapshot = doc_ref.get()
assert snapshot.to_dict()[key] == expected


@pytest.mark.parametrize("with_rollback,expected", [(True, 2), (False, 3)])
@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
def test_transaction_rollback(client, cleanup, database, with_rollback, expected):
Expand Down
Loading