From 86aad064377babd45da1f258fb5838b56382d84f Mon Sep 17 00:00:00 2001 From: brimoor Date: Wed, 4 Sep 2024 00:09:21 -0400 Subject: [PATCH] tweak --- fiftyone/core/odm/document.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fiftyone/core/odm/document.py b/fiftyone/core/odm/document.py index b263e5bacb..c847fc8384 100644 --- a/fiftyone/core/odm/document.py +++ b/fiftyone/core/odm/document.py @@ -9,7 +9,6 @@ from copy import deepcopy import json -import bson from bson import json_util, ObjectId import mongoengine from pymongo import InsertOne, UpdateOne @@ -588,21 +587,19 @@ def copy(self, new_id=False): """Returns a deep copy of the document. Args: - new_id (False): Whether to generate a new ID for the copied - document locally. By default, ID is set to None which causes - ID generation to be done on the server. + new_id (False): whether to generate a new ID for the copied + document. By default, the ID is left as ``None`` and will be + automatically populated when the document is added to the + database """ doc_copy = super().copy() - if new_id: - new_id = bson.ObjectId() + if new_id: # pylint: disable=no-member id_field = self._meta.get("id_field", "id") - doc_copy.set_field(id_field, new_id) - - # Setting _created explicitly as True because we know this is a new - # document + doc_copy.set_field(id_field, ObjectId()) doc_copy._created = True + return doc_copy def reload(self, *fields, **kwargs):