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
24 changes: 15 additions & 9 deletions collector_db/AsyncDatabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,20 +1573,26 @@ async def get_recent_batch_status_info(
limit = 100
query = Select(Batch)
if has_pending_urls is not None:
pending_url_subquery = Select(URL).where(
and_(
URL.batch_id == Batch.id,
URL.outcome == URLStatus.PENDING.value
)
)

if has_pending_urls:
# Query for all that have pending URLs
query = query.join(URL, Batch.id == URL.batch_id).filter(URL.outcome == URLStatus.PENDING.value)
query = query.where(exists(
pending_url_subquery
))
else:
# Query for all that DO NOT have pending URLs
# (or that have no URLs at all)
query = query.join(
URL,
Batch.id == URL.batch_id,
isouter=True
).filter(
or_(
URL.outcome != URLStatus.PENDING.value,
URL.outcome.is_(None)
query = query.where(
not_(
exists(
pending_url_subquery
)
)
)
if collector_type:
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/DBDataCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from random import randint
from typing import List, Optional

from pydantic import BaseModel
from pydantic import BaseModel, model_validator

Check warning on line 5 in tests/helpers/DBDataCreator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/helpers/DBDataCreator.py#L5 <401>

'pydantic.model_validator' imported but unused
Raw output
./tests/helpers/DBDataCreator.py:5:1: F401 'pydantic.model_validator' imported but unused

from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
from collector_db.DTOs.BatchInfo import BatchInfo
Expand Down
10 changes: 5 additions & 5 deletions tests/test_automated/integration/api/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ async def test_get_batch_status_pending_url_filter(api_test_helper):
# Add an errored out batch
batch_error = await ath.db_data_creator.batch_and_urls(
strategy=CollectorType.EXAMPLE,
url_count=1,
url_count=2,
batch_status=BatchStatus.ERROR
)

# Add a batch with pending urls
batch_pending = await ath.db_data_creator.batch_and_urls(
strategy=CollectorType.EXAMPLE,
url_count=1,
url_count=2,
batch_status=BatchStatus.READY_TO_LABEL,
with_html_content=True,
url_status=URLStatus.PENDING
Expand All @@ -32,7 +32,7 @@ async def test_get_batch_status_pending_url_filter(api_test_helper):
# Add a batch with submitted URLs
batch_submitted = await ath.db_data_creator.batch_and_urls(
strategy=CollectorType.EXAMPLE,
url_count=1,
url_count=2,
batch_status=BatchStatus.READY_TO_LABEL,
with_html_content=True,
url_status=URLStatus.SUBMITTED
Expand All @@ -41,14 +41,14 @@ async def test_get_batch_status_pending_url_filter(api_test_helper):
# Add an aborted batch
batch_aborted = await ath.db_data_creator.batch_and_urls(
strategy=CollectorType.EXAMPLE,
url_count=1,
url_count=2,
batch_status=BatchStatus.ABORTED
)

# Add a batch with validated URLs
batch_validated = await ath.db_data_creator.batch_and_urls(
strategy=CollectorType.EXAMPLE,
url_count=1,
url_count=2,
batch_status=BatchStatus.READY_TO_LABEL,
with_html_content=True,
url_status=URLStatus.VALIDATED
Expand Down