Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pytest
pytest-asyncio
pytest-cov
httpx
mongomock
pytest-mock
freezegun

# Static code analysis
flake8
Expand Down
15 changes: 12 additions & 3 deletions backend/services/data_documents_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,18 @@ def update_document(
except Exception:
pass
before_doc = collection.find_one({"_id": ObjectId(document_id)})
result = collection.update_one(
{"_id": ObjectId(document_id)}, {"$set": content}
)
if not before_doc:
return None

# Preserve datetime_creation from the existing document
if "datetime_creation" in before_doc:
content["datetime_creation"] = before_doc["datetime_creation"]

# Always update datetime_last_modified to current time
content["datetime_last_modified"] = datetime.now(timezone.utc)

# Use replace_one to completely replace the document while preserving system fields
result = collection.replace_one({"_id": ObjectId(document_id)}, content)
if result.matched_count == 0:
return None
updated_doc = collection.find_one({"_id": ObjectId(document_id)})
Expand Down
Loading