Make Query.set_limits a setter
|Reported by:||jorgecarleitao||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Query.set_limits(low=None, high=None) is used to create LIMIT low OFFSET high - low.
However, as pointed out in this thread, it *adds* to the limits and doesn't *set* the limits.
Since Query is responsible for storing the SQL expression to be generated, I propose Query.set_limits to be the interface to set the limits of the query, and make QuerySet responsible for adding the limits if required. I.e. I propose that set_limits overrides the previous limits. In particular the following becomes equivalent:
Query.set_limits(a, b).set_limits(c, d) Query.set_limits(c, b)
Currently this method is used in:
- QuerySet._earliest_or_latest (calls clone.query.set_limits(high=1))
- Query.has_results (calls clone.set_limits(high=1))
and QuerySet doesn't seem to be using the add part anyway: neither _earliest_or_latest (i.e. the methods that use it) nor __getitem__ return a new QuerySet.
Change History (4)
comment:1 Changed 16 months ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed