Accept empty MongoDB trace batches without inserting
This commit is contained in:
parent
63825de2f9
commit
ff989fd6ee
2 changed files with 8 additions and 0 deletions
|
|
@ -75,6 +75,8 @@ class MongoDbDriver(TracingDatabaseDriver):
|
|||
return client[self.mongo_database].traces.insert_one(serialized).inserted_id
|
||||
|
||||
def save_batch(self, documents: List[Trace]) -> List[str]:
|
||||
if not documents:
|
||||
return []
|
||||
serialized = [d.to_flat_dict() for d in documents]
|
||||
for s in serialized:
|
||||
s["_id"] = s["trace_id"]
|
||||
|
|
|
|||
|
|
@ -38,3 +38,9 @@ def test_zero_take_preserves_count_without_fetching(
|
|||
driver, collection = mongo
|
||||
assert driver.query(take=0) == ([], 3)
|
||||
collection.find.assert_not_called()
|
||||
|
||||
|
||||
def test_empty_batch_is_a_noop(mongo: Tuple[MongoDbDriver, Any]) -> None:
|
||||
driver, collection = mongo
|
||||
assert driver.save_batch([]) == []
|
||||
collection.insert_many.assert_not_called()
|
||||
|
|
|
|||
Loading…
Reference in a new issue