Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Sep 4, 2024
1 parent 63a5cc4 commit 86aad06
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions fiftyone/core/odm/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 86aad06

Please sign in to comment.