File tree Expand file tree Collapse file tree 3 files changed +831
-3
lines changed Expand file tree Collapse file tree 3 files changed +831
-3
lines changed Original file line number Diff line number Diff line change 1414pytest-asyncio
1515pytest-cov
1616httpx
17+ mongomock
18+ pytest-mock
19+ freezegun
1720
1821# Static code analysis
1922flake8
Original file line number Diff line number Diff line change @@ -207,9 +207,18 @@ def update_document(
207207 except Exception :
208208 pass
209209 before_doc = collection .find_one ({"_id" : ObjectId (document_id )})
210- result = collection .update_one (
211- {"_id" : ObjectId (document_id )}, {"$set" : content }
212- )
210+ if not before_doc :
211+ return None
212+
213+ # Preserve datetime_creation from the existing document
214+ if "datetime_creation" in before_doc :
215+ content ["datetime_creation" ] = before_doc ["datetime_creation" ]
216+
217+ # Always update datetime_last_modified to current time
218+ content ["datetime_last_modified" ] = datetime .now (timezone .utc )
219+
220+ # Use replace_one to completely replace the document while preserving system fields
221+ result = collection .replace_one ({"_id" : ObjectId (document_id )}, content )
213222 if result .matched_count == 0 :
214223 return None
215224 updated_doc = collection .find_one ({"_id" : ObjectId (document_id )})
You can’t perform that action at this time.
0 commit comments