Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish FieldPath classes from field path strings #4466

Merged
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
14 changes: 9 additions & 5 deletions firestore/google/cloud/firestore_v1beta1/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def to_api_repr(self):
"""
api_repr = []
for part in self.parts:
if re.match(self.simple_field_name, part):
match = re.match(self.simple_field_name, part)
if match and match.group(0) == part:
api_repr.append(part)
else:
replaced = part.replace('\\', '\\\\').replace('`', '\\`')
Expand Down Expand Up @@ -281,14 +282,15 @@ def path_end_conflict(self, field_path, conflicting_paths):
Returns:
ValueError: Always.
"""
conflict_parts = [field_path]
conflict_parts = list(field_path.parts)
while conflicting_paths is not self.PATH_END:
# Grab any item, we are just looking for one example.
part, conflicting_paths = next(six.iteritems(conflicting_paths))
conflict_parts.append(part)

conflict = get_field_path(conflict_parts)
msg = self.FIELD_PATH_CONFLICT.format(field_path, conflict)
msg = self.FIELD_PATH_CONFLICT.format(
field_path.to_api_repr(), conflict)
return ValueError(msg)

def add_field_path_end(
Expand Down Expand Up @@ -340,7 +342,9 @@ def add_value_at_field_path(self, field_path, value):
Raises:
ValueError: If there is an ambiguity.
"""
parts = parse_field_path(field_path)
if isinstance(field_path, six.string_types):
field_path = FieldPath.from_string(field_path)
parts = field_path.parts
to_update = self.get_update_values(value)
curr_paths = self.unpacked_field_paths
for index, part in enumerate(parts[:-1]):
Expand Down Expand Up @@ -912,7 +916,7 @@ def canonicalize_field_paths(field_paths):

.. _Document: https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Document # NOQA
"""
return [FieldPath.from_string(path).to_api_repr() for path in field_paths]
return [path.to_api_repr() for path in field_paths]


def pbs_for_update(client, document_path, field_updates, option):
Expand Down
Loading