From af48cad39e7aac02ab5c7120b4509abd4b1941cd Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 21 Apr 2010 23:50:00 +0000 Subject: [PATCH] [1.1.X] Fixed #13396 -- Modified the SQLite introspection code to avoid a problem with unconsumed cursors on PyPy. Thanks to Alex Gaynor for the report and fix. Backport of r13016 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@13017 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/sqlite3/introspection.py | 2 +- tests/regressiontests/introspection/tests.py | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index b58e6a7faf..83591b7185 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -65,7 +65,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): relations = {} # Schema for this table - cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table_name]) + cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) results = cursor.fetchone()[0].strip() results = results[results.index('(')+1:results.rindex(')')] diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py index 1454e1e3e5..394ebcb636 100644 --- a/tests/regressiontests/introspection/tests.py +++ b/tests/regressiontests/introspection/tests.py @@ -5,11 +5,6 @@ from django.utils import functional from models import Reporter, Article -try: - set -except NameError: - from sets import Set as set # Python 2.3 fallback - # # The introspection module is optional, so methods tested here might raise # NotImplementedError. This is perfectly acceptable behavior for the backend @@ -76,8 +71,10 @@ class IntrospectionTests(TestCase): def test_get_table_description_types(self): cursor = connection.cursor() desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table) - self.assertEqual([datatype(r[1], r) for r in desc], - ['IntegerField', 'CharField', 'CharField', 'CharField']) + self.assertEqual( + [datatype(r[1], r) for r in desc], + ['IntegerField', 'CharField', 'CharField', 'CharField'] + ) # Regression test for #9991 - 'real' types in postgres if settings.DATABASE_ENGINE.startswith('postgresql'):