Skip to content

Commit afaa7f2

Browse files
authored
feat: remove _id check for inserts (#148)
* feat: do not require _id for managed collection * test: update unit tests * feat: remove _id check for inserts
1 parent 693f660 commit afaa7f2

File tree

2 files changed

+0
-20
lines changed

2 files changed

+0
-20
lines changed

src/aind_data_access_api/document_db.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ def aggregate_docdb_records(self, pipeline: List[dict]) -> List[dict]:
429429

430430
def insert_one_docdb_record(self, record: dict) -> Response:
431431
"""Insert one new record"""
432-
if record.get("_id") is None:
433-
raise ValueError("Record does not have an _id field.")
434432
response = self._insert_one_record(
435433
json.loads(json.dumps(record, default=str)),
436434
)

tests/test_document_db.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -579,24 +579,6 @@ def test_insert_one_docdb_record(self, mock_insert: MagicMock):
579579
json.loads(json.dumps(record, default=str)),
580580
)
581581

582-
@patch("aind_data_access_api.document_db.Client._insert_one_record")
583-
def test_insert_one_docdb_record_invalid(self, mock_insert: MagicMock):
584-
"""Tests inserting one docdb record if record is invalid"""
585-
client = MetadataDbClient(**self.example_client_args)
586-
record_no__id = {
587-
"id": "abc-123",
588-
"name": "modal_00000_2000-10-10_10-10-10",
589-
"created": datetime(2000, 10, 10, 10, 10, 10),
590-
"location": "some_url",
591-
"subject": {"subject_id": "00000", "sex": "Female"},
592-
}
593-
with self.assertRaises(ValueError) as e:
594-
client.insert_one_docdb_record(record_no__id)
595-
self.assertEqual(
596-
"Record does not have an _id field.", str(e.exception)
597-
)
598-
mock_insert.assert_not_called()
599-
600582
@patch("aind_data_access_api.document_db.Client._upsert_one_record")
601583
def test_upsert_one_docdb_record(self, mock_upsert: MagicMock):
602584
"""Tests upserting one docdb record"""

0 commit comments

Comments
 (0)