diff --git a/spoolman/database/filament.py b/spoolman/database/filament.py index 8ce838490..ae8c26e36 100644 --- a/spoolman/database/filament.py +++ b/spoolman/database/filament.py @@ -107,7 +107,7 @@ async def find( total_count = None if limit is not None: - total_count_stmt = stmt.with_only_columns(func.count()) + total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True) total_count = (await db.execute(total_count_stmt)).scalar() stmt = stmt.offset(offset).limit(limit) diff --git a/spoolman/database/spool.py b/spoolman/database/spool.py index 08d97f774..e04538e20 100644 --- a/spoolman/database/spool.py +++ b/spoolman/database/spool.py @@ -132,7 +132,7 @@ async def find( total_count = None if limit is not None: - total_count_stmt = stmt.with_only_columns(func.count()) + total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True) total_count = (await db.execute(total_count_stmt)).scalar() stmt = stmt.offset(offset).limit(limit) diff --git a/spoolman/database/vendor.py b/spoolman/database/vendor.py index 120c061fe..d0e603941 100644 --- a/spoolman/database/vendor.py +++ b/spoolman/database/vendor.py @@ -53,7 +53,7 @@ async def find( total_count = None if limit is not None: - total_count_stmt = stmt.with_only_columns(func.count()) + total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True) total_count = (await db.execute(total_count_stmt)).scalar() stmt = stmt.offset(offset).limit(limit) diff --git a/tests_integration/tests/filament/test_find.py b/tests_integration/tests/filament/test_find.py index c4b01945d..4f34fa99e 100644 --- a/tests_integration/tests/filament/test_find.py +++ b/tests_integration/tests/filament/test_find.py @@ -165,6 +165,7 @@ def test_find_all_filaments_limit_asc(filaments: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" filaments_result = result.json() assert len(filaments_result) == 2 assert filaments_result == [filaments.filaments[0], filaments.filaments[1]] @@ -176,6 +177,7 @@ def test_find_all_filaments_limit_desc(filaments: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" filaments_result = result.json() assert len(filaments_result) == 2 assert filaments_result == [filaments.filaments[-1], filaments.filaments[-2]] @@ -187,6 +189,7 @@ def test_find_all_filaments_limit_asc_offset(filaments: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" filaments_result = result.json() assert len(filaments_result) == 2 assert filaments_result == [filaments.filaments[1], filaments.filaments[2]] @@ -198,6 +201,7 @@ def test_find_all_filaments_limit_desc_offset(filaments: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" filaments_result = result.json() assert len(filaments_result) == 2 assert filaments_result == [filaments.filaments[-2], filaments.filaments[-3]] @@ -209,6 +213,7 @@ def test_find_all_filaments_limit_asc_offset_outside_range(filaments: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" filaments_result = result.json() assert len(filaments_result) == 0 diff --git a/tests_integration/tests/spool/test_find.py b/tests_integration/tests/spool/test_find.py index ae3373110..34d3738a3 100644 --- a/tests_integration/tests/spool/test_find.py +++ b/tests_integration/tests/spool/test_find.py @@ -162,6 +162,7 @@ def test_find_all_spools_limit_asc(spools: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "4" spools_result = result.json() assert len(spools_result) == 2 assert spools_result == [spools.spools[0], spools.spools[1]] @@ -173,6 +174,7 @@ def test_find_all_spools_limit_desc(spools: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "4" spools_result = result.json() assert len(spools_result) == 2 assert spools_result == [spools.spools[-1], spools.spools[-2]] @@ -184,6 +186,7 @@ def test_find_all_spools_limit_asc_offset(spools: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" spools_result = result.json() assert len(spools_result) == 2 assert spools_result == [spools.spools[1], spools.spools[2]] @@ -195,6 +198,7 @@ def test_find_all_spools_limit_desc_offset(spools: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "5" spools_result = result.json() assert len(spools_result) == 2 assert spools_result == [spools.spools[-2], spools.spools[-3]] @@ -206,6 +210,7 @@ def test_find_all_spools_limit_asc_offset_outside_range(spools: Fixture): # noq result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "4" spools_result = result.json() assert len(spools_result) == 0 diff --git a/tests_integration/tests/vendor/test_find.py b/tests_integration/tests/vendor/test_find.py index 3506f6a24..49dff8a26 100644 --- a/tests_integration/tests/vendor/test_find.py +++ b/tests_integration/tests/vendor/test_find.py @@ -93,6 +93,7 @@ def test_find_all_vendors_limit_asc(vendors: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "3" vendors_result = result.json() assert len(vendors_result) == 2 assert vendors_result == [vendors.vendors[0], vendors.vendors[1]] @@ -104,6 +105,7 @@ def test_find_all_vendors_limit_desc(vendors: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "3" vendors_result = result.json() assert len(vendors_result) == 2 assert vendors_result == [vendors.vendors[-1], vendors.vendors[-2]] @@ -115,6 +117,7 @@ def test_find_all_vendors_limit_asc_offset(vendors: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "3" vendors_result = result.json() assert len(vendors_result) == 2 assert vendors_result == [vendors.vendors[1], vendors.vendors[2]] @@ -126,6 +129,7 @@ def test_find_all_vendors_limit_desc_offset(vendors: Fixture): result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "3" vendors_result = result.json() assert len(vendors_result) == 2 assert vendors_result == [vendors.vendors[-2], vendors.vendors[-3]] @@ -137,6 +141,7 @@ def test_find_all_vendors_limit_asc_offset_outside_range(vendors: Fixture): # n result.raise_for_status() # Verify + assert result.headers["X-Total-Count"] == "3" vendors_result = result.json() assert len(vendors_result) == 0