Skip to content

Commit

Permalink
Fix: use subquery() in count_matching_* accessors
Browse files Browse the repository at this point in the history
Fixes a SQLAlchemy deprecation warning.
  • Loading branch information
odesenfans committed Nov 3, 2023
1 parent 832b0bd commit 2b73eb5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/aleph/db/accessors/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ def count_matching_posts(
pagination=0,
start_date=start_date,
end_date=end_date,
)
).subquery()
else:
# Without filters, counting the number of original posts is faster.
select_stmt = select(PostDb).where(PostDb.amends.is_(None))
select_stmt = select(PostDb).where(PostDb.amends.is_(None)).subquery()

select_count_stmt = select(func.count()).select_from(select_stmt)
return session.execute(select_count_stmt).scalar_one()
Expand Down
3 changes: 1 addition & 2 deletions tests/api/test_list_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ async def test_get_messages(fixture_messages: Sequence[Dict[str, Any]], ccn_api_
async def test_get_messages_filter_by_channel(fixture_messages, ccn_api_client):
async def fetch_messages_by_channel(channel: str) -> Dict:
response = await ccn_api_client.get(MESSAGES_URI, params={"channels": channel})
text = await response.text()
assert response.status == 200, text
assert response.status == 200, await response.text()
return await response.json()

data = await fetch_messages_by_channel("unit-tests")
Expand Down

0 comments on commit 2b73eb5

Please sign in to comment.