@@ -819,54 +819,35 @@ def process_server_timestamp(document_data, split_on_dots=True):
819819 * The remaining keys in ``document_data`` after removing the
820820 server timestamp sentinels
821821 """
822+ field_paths = []
822823 transform_paths = []
823824 actual_data = {}
824825 for field_name , value in six .iteritems (document_data ):
825826 if isinstance (value , dict ):
826- sub_field_paths , sub_data = process_server_timestamp (value , False )
827- for sub_path in sub_field_paths :
827+ sub_transform_paths , sub_data , sub_field_paths = process_server_timestamp (value , False )
828+ for sub_path in sub_transform_paths :
828829 field_path = FieldPath .from_string (field_name )
829830 field_path .parts = field_path .parts + sub_path .parts
830831 transform_paths .extend ([field_path ])
831832 if sub_data :
832833 # Only add a key to ``actual_data`` if there is data.
834+
833835 actual_data [field_name ] = sub_data
836+ for sub_field_path in sub_field_paths :
837+ field_path = FieldPath .from_string (field_name )
838+ field_path .parts = field_path .parts + sub_field_path .parts
839+ field_paths .append (field_path )
834840 elif value is constants .SERVER_TIMESTAMP :
835841 if split_on_dots :
836842 transform_paths .append (FieldPath (* field_name .split ("." )))
837843 else :
838844 transform_paths .append (FieldPath .from_string (field_name ))
839845 else :
840846 actual_data [field_name ] = value
847+ field_paths .append (FieldPath (field_name ))
841848 if not transform_paths :
842849 actual_data = document_data
843- return transform_paths , actual_data
844-
845-
846- def extract_field_paths (document_data ):
847- """Extract field paths from document data
848-
849- Args:
850- document_data (dict): The dictionary of the actual set data.
851-
852- Returns:
853- List[~.firestore_v1beta1._helpers.FieldPath]:
854- A list of `FieldPath` instances from the actual data.
855- """
856- field_paths = []
857- for field_name , value in six .iteritems (document_data ):
858- if isinstance (value , dict ):
859- sub_field_paths = extract_field_paths (value )
860- for sub_path in sub_field_paths :
861- paths = [field_name ]
862- paths .extend (sub_path .parts )
863- field_path = FieldPath (* paths )
864- field_paths .append (field_path )
865- else :
866- path = FieldPath (field_name )
867- field_paths .append (path )
868- return field_paths
869-
850+ return transform_paths , actual_data , field_paths
870851
871852
872853def get_transform_pb (document_path , transform_paths ):
@@ -913,7 +894,7 @@ def pbs_for_set(document_path, document_data, merge=False, exists=None):
913894 List[google.cloud.firestore_v1beta1.types.Write]: One
914895 or two ``Write`` protobuf instances for ``set()``.
915896 """
916- transform_paths , actual_data = process_server_timestamp (
897+ transform_paths , actual_data , field_paths = process_server_timestamp (
917898 document_data , False )
918899 update_pb = write_pb2 .Write (
919900 update = document_pb2 .Document (
@@ -926,7 +907,6 @@ def pbs_for_set(document_path, document_data, merge=False, exists=None):
926907 common_pb2 .Precondition (exists = exists ))
927908
928909 if merge :
929- field_paths = extract_field_paths (document_data )
930910 field_paths = canonicalize_field_paths (field_paths )
931911 mask = common_pb2 .DocumentMask (field_paths = sorted (field_paths ))
932912 update_pb .update_mask .CopyFrom (mask )
@@ -985,7 +965,7 @@ def pbs_for_update(client, document_path, field_updates, option):
985965 # Default uses ``exists=True``.
986966 option = client .write_option (exists = True )
987967
988- transform_paths , actual_updates = process_server_timestamp (field_updates )
968+ transform_paths , actual_updates , field_paths = process_server_timestamp (field_updates )
989969 if not (transform_paths or actual_updates ):
990970 raise ValueError ('There are only ServerTimeStamp objects or is empty.' )
991971 update_values , field_paths = FieldPathHelper .to_field_paths (actual_updates )
0 commit comments