Skip to content

Commit 74af346

Browse files
author
Melvyn Sopacua
committed
fix(1.11): fetch_many() and fetch_all() must not fail
These two methods shall return empty lists when no rows are available. In MS SQL Server (or pyodcb), they are generating an exception, which - among other things - breaks standard Django migrations.
1 parent b54fc20 commit 74af346

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setup(
2121
name='django-pyodbc-azure',
22-
version='1.11.15.0',
22+
version='1.11.15.1',
2323
description='Django backend for Microsoft SQL Server and Azure SQL Database using pyodbc',
2424
long_description=open('README.rst').read(),
2525
author='Michiya Takahashi',

sql_server/pyodbc/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
from django.conf import settings
2424
from django.db.backends.base.base import BaseDatabaseWrapper
25-
from django.db.backends.base.validation import BaseDatabaseValidation
25+
from django.db.utils import ProgrammingError
2626
from django.utils.encoding import smart_str
2727
from django.utils.functional import cached_property
2828
from django.utils.six import binary_type, text_type
29-
from django.utils.timezone import utc
3029

3130
if hasattr(settings, 'DATABASE_CONNECTION_POOLING'):
3231
if not settings.DATABASE_CONNECTION_POOLING:
@@ -605,10 +604,16 @@ def fetchone(self):
605604
return row
606605

607606
def fetchmany(self, chunk):
608-
return self.format_rows(self.cursor.fetchmany(chunk))
607+
try:
608+
return self.format_rows(self.cursor.fetchmany(chunk))
609+
except ProgrammingError:
610+
return []
609611

610612
def fetchall(self):
611-
return self.format_rows(self.cursor.fetchall())
613+
try:
614+
return self.format_rows(self.cursor.fetchall())
615+
except ProgrammingError:
616+
return []
612617

613618
def __getattr__(self, attr):
614619
if attr in self.__dict__:

0 commit comments

Comments
 (0)