Skip to content

Commit

Permalink
Review Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelnucfin committed Mar 19, 2018
1 parent d0f9e01 commit 984eed5
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 66 deletions.
16 changes: 9 additions & 7 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 All @@ -362,8 +366,6 @@ def parse(self):
* The list of field paths to send (for updates and deletes).
"""
for key, value in six.iteritems(self.field_updates):
if isinstance(key, FieldPath):
key = key.to_api_repr()
self.add_value_at_field_path(key, value)

return self.update_values, self.field_paths
Expand Down Expand Up @@ -914,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

0 comments on commit 984eed5

Please sign in to comment.