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
4 changes: 2 additions & 2 deletions advanced_alchemy/repository/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,15 +1503,15 @@ async def list_and_count(
Returns:
Count of records returned by query, ignoring pagination.
"""
self.count_with_window_function = (
count_with_window_function = (
count_with_window_function if count_with_window_function is not None else self.count_with_window_function
)
self.uniquify = self._get_uniquify(uniquify)
error_messages = self._get_error_messages(
error_messages=error_messages,
default_messages=self.error_messages,
)
if self._dialect.name in {"spanner", "spanner+spanner"} or count_with_window_function:
if self._dialect.name in {"spanner", "spanner+spanner"} or not count_with_window_function:
return await self._list_and_count_basic(
*filters,
auto_expunge=auto_expunge,
Expand Down
4 changes: 2 additions & 2 deletions advanced_alchemy/repository/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,15 +1504,15 @@ def list_and_count(
Returns:
Count of records returned by query, ignoring pagination.
"""
self.count_with_window_function = (
count_with_window_function = (
count_with_window_function if count_with_window_function is not None else self.count_with_window_function
)
self.uniquify = self._get_uniquify(uniquify)
error_messages = self._get_error_messages(
error_messages=error_messages,
default_messages=self.error_messages,
)
if self._dialect.name in {"spanner", "spanner+spanner"} or count_with_window_function:
if self._dialect.name in {"spanner", "spanner+spanner"} or not count_with_window_function:
return self._list_and_count_basic(
*filters,
auto_expunge=auto_expunge,
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ async def test_sqlalchemy_repo_list_and_count(mock_repo: SQLAlchemyAsyncReposito
"""Test expected method calls for list operation."""
mock_instances = [MagicMock(), MagicMock()]
mock_count = len(mock_instances)
mocker.patch.object(mock_repo, "_list_and_count_basic", return_value=(mock_instances, mock_count))
mocker.patch.object(mock_repo, "_list_and_count_window", return_value=(mock_instances, mock_count))

instances, instance_count = await maybe_async(mock_repo.list_and_count())
Expand All @@ -546,9 +545,8 @@ async def test_sqlalchemy_repo_list_and_count_basic(
mock_instances = [MagicMock(), MagicMock()]
mock_count = len(mock_instances)
mocker.patch.object(mock_repo, "_list_and_count_basic", return_value=(mock_instances, mock_count))
mocker.patch.object(mock_repo, "_list_and_count_window", return_value=(mock_instances, mock_count))

instances, instance_count = await maybe_async(mock_repo.list_and_count(count_with_window_function=True))
instances, instance_count = await maybe_async(mock_repo.list_and_count(count_with_window_function=False))

assert instances == mock_instances
assert instance_count == mock_count
Expand Down