Commit 403a4dc
authored
fix: clamp count() at 0 when offset exceeds total (#2208)
* fix: clamp count() to limit/offset semantics at the edges
COUNT(*) ignores LIMIT/OFFSET, so CountQuery applies them in Python. Two edge
cases didn't match the limited query result:
- offset greater than the total returned a negative number (e.g.
.offset(100).count() == -95 for 5 rows) instead of 0.
- limit(0) returned the full total instead of 0, because the limit clamp used
a truthiness check (`if self._limit`) that skips 0.
Clamp the offset subtraction at 0 and use `self._limit is not None` so an
explicit limit(0) is honored.
* docs: reference count fix PR in changelog
* test: format count edge assertions1 parent 179ea6f commit 403a4dc
3 files changed
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
| |||
106 | 114 | | |
107 | 115 | | |
108 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | | - | |
1575 | | - | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
1576 | 1581 | | |
1577 | 1582 | | |
1578 | 1583 | | |
| |||
0 commit comments