tortoise / tortoise/tortoise-orm
Ignoring offset and limit when creating count SQL request
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
Suppose I get a slice from the database specifying LIMIT and OFFSET values, I generate a query, but if instead of the first() or all() result specifying count(), the query ignores my specified parameters.
To Reproduce
body = (
Service.filter(status=ServiceStatus.ACTIVE)
.offset(3)
.limit(5)
)
Example of the SQL query
Expected behavior
So, we make
await body.count()
If we add .sql() and make
body.count().sql()
then we get
SELECT COUNT(*) FROM "services" WHERE "status"='ACTIVE'
but as i think we need to get something like that:
SELECT COUNT(*) FROM "services" WHERE "status"='ACTIVE' LIMIT 5 OFFSET 0
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Service.filter(...).offset(3).limit(5) example and inspect the SQL generated by count(). Trace the ORM's count-query generation and its handling of offset and limit. Done means the intended behavior is documented by a regression test and the generated count SQL matches that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100