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: 2 additions & 1 deletion src/bloomy/utils/abstract_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from collections.abc import Callable
from typing import Any

from ..models import BulkCreateError, BulkCreateResult
Expand Down Expand Up @@ -70,7 +71,7 @@ def _validate_bulk_item(
def _process_bulk_sync[T](
self,
items: list[dict[str, Any]],
create_func: Any,
create_func: Callable[[dict[str, Any]], T],
required_fields: list[str],
) -> BulkCreateResult[T]:
"""Process bulk creation synchronously.
Expand Down
23 changes: 23 additions & 0 deletions tests/test_abstract_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,26 @@ def test_prepare_params(self) -> None:
# Test with all None values
params = ops._prepare_params(a=None, b=None)
assert params == {}

def test_process_bulk_sync_create_func_signature(self) -> None:
"""_process_bulk_sync accepts Callable[[dict[str, Any]], T] create_func."""
client = MockHTTPClient()
ops = ConcreteOperations(client)

def create_func(item_data: dict) -> str:
return f"created-{item_data['title']}"

result = ops._process_bulk_sync(
[
{"title": "a"},
{"title": "b"},
{}, # missing required field
],
create_func,
required_fields=["title"],
)

assert result.successful == ["created-a", "created-b"]
assert len(result.failed) == 1
assert result.failed[0].index == 2
assert "title" in result.failed[0].error
Loading