1. Michael Manfre
  2. django-mssql
  3. Pull requests

Pull requests

#10 Declined
Repository
rlmuraya
Branch
1.8-fix
Repository
Manfre
Branch
master

1.8.x - Fix evaluation of zero-length query slices

Author
  1. Rebecca Muraya
Reviewers
Description

See Django #25894. A bug occurs for zero-length slices of a QuerySet (e.g., Model.objects.all()[0:0]). It was a bug in Django 1.9 that was fixed in an early point release, but the bug can be seen using Oracle and, apparently, MSSQL backends on Django 1.8.

This Django PR fixed the problem for Oracle on Django >= 1.9: https://github.com/django/django/pull/5834

Since the above PR was not backported to 1.8, I had to monkey-patch the Query class to fully fix the problem on my project:

def set_limits(self, low=None, high=None):
    self._original_set_limits(low, high)
    if self.low_mark == self.high_mark:
        self.set_empty()

from django.db.models.sql.query import Query
Query._original_set_limits = Query.set_limits
Query.set_limits = set_limits

Comments (2)