Skip to content

Commit 5468487

Browse files
committed
clean up inconsistent singleton stuff
1 parent 789802a commit 5468487

File tree

5 files changed

+11
-24
lines changed

5 files changed

+11
-24
lines changed

poliloom/poliloom/enrichment.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ async def extract_two_stage_generic(
345345
content: str,
346346
politician: Politician,
347347
config: TwoStageExtractionConfig,
348-
search_service: Optional[SearchService] = None,
349348
) -> Optional[List[Any]]:
350349
"""Generic two-stage extraction (free-form -> mapping).
351350
@@ -355,11 +354,8 @@ async def extract_two_stage_generic(
355354
content: Text content to extract from
356355
politician: Politician being enriched
357356
config: Extraction configuration
358-
search_service: SearchService for entity lookup (creates new instance if not provided)
359357
"""
360-
# Use provided search service or create new instance
361-
if search_service is None:
362-
search_service = SearchService()
358+
search_service = SearchService()
363359

364360
try:
365361
# Stage 1: Free-form extraction

poliloom/poliloom/importer/politician.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def _insert_politicians_batch(
212212
session.commit()
213213

214214
# Index to Meilisearch after successful DB commit
215-
search_service.index_documents(search_documents)
215+
if search_documents:
216+
search_service.index_documents(search_documents)
216217

217218
logger.debug(f"Processed {len(politicians)} politicians (upserted)")
218219

poliloom/tests/test_enrichment.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,12 @@ async def mock_parse(*args, **kwargs):
237237

238238
mock_openai_client.responses.parse = mock_parse
239239

240-
# Search service is passed but find_similar is mocked globally
241-
mock_search_service = Mock()
242-
243240
birthplaces = await extract_two_stage_generic(
244241
mock_openai_client,
245242
db_session,
246243
"test content",
247244
sample_politician,
248245
BIRTHPLACES_CONFIG,
249-
search_service=mock_search_service,
250246
)
251247

252248
assert birthplaces is not None

poliloom/tests/test_entity_importer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ def test_insert_empty_batch_does_not_call_index(
534534
# index_documents should not be called for empty batch
535535
mock_search_service.index_documents.assert_not_called()
536536

537-
def test_insert_entities_without_labels_indexes_empty_labels(
537+
def test_insert_entities_without_labels_does_not_index(
538538
self, db_session, mock_search_service
539539
):
540-
"""Test that entities without labels are indexed with empty labels list."""
540+
"""Test that entities without labels are not indexed."""
541541
locations = [
542542
{
543543
"wikidata_id": "Q1",
@@ -553,10 +553,8 @@ def test_insert_entities_without_labels_indexes_empty_labels(
553553

554554
collection.insert(db_session, mock_search_service)
555555

556-
# Should still call index_documents
557-
mock_search_service.index_documents.assert_called_once()
558-
call_args = mock_search_service.index_documents.call_args[0][0]
559-
assert call_args[0]["labels"] == []
556+
# index_documents should not be called when no entities have labels
557+
mock_search_service.index_documents.assert_not_called()
560558

561559

562560
class TestWikipediaProjectFiltering:

poliloom/tests/test_politician_importer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ def test_insert_politicians_empty_batch_does_not_call_index(
482482
# index_documents should not be called for empty batch
483483
mock_search_service.index_documents.assert_not_called()
484484

485-
def test_insert_politicians_without_labels_indexes_empty_labels(
485+
def test_insert_politicians_without_labels_does_not_index(
486486
self, db_session, mock_search_service
487487
):
488-
"""Test that politicians without labels are indexed with empty labels list."""
488+
"""Test that politicians without labels are not indexed."""
489489
politicians = [
490490
{
491491
"wikidata_id": "Q1",
@@ -498,12 +498,8 @@ def test_insert_politicians_without_labels_indexes_empty_labels(
498498

499499
_insert_politicians_batch(politicians, db_session, mock_search_service)
500500

501-
# Should still call index_documents
502-
mock_search_service.index_documents.assert_called_once()
503-
call_args = mock_search_service.index_documents.call_args[0][0]
504-
assert call_args[0]["id"] == "Q1"
505-
assert call_args[0]["type"] == "politicians"
506-
assert call_args[0]["labels"] == []
501+
# index_documents should not be called when no entities have labels
502+
mock_search_service.index_documents.assert_not_called()
507503

508504

509505
class TestIsPolitician:

0 commit comments

Comments
 (0)