From 3de70a10c0668ad7f2f1da335ab515faea90b5fb Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sat, 31 May 2008 01:01:17 +0000 Subject: [PATCH] Fixed #6820: flush no longer fails under PostgreSQL 8.3. WARNING: In the process I renamed a couple of internal functions in django.core.management.sql, so this is a backwards-incompatible change if you were using those internal functions. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7568 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management/commands/syncdb.py | 4 ++-- django/core/management/sql.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py index 8017ed832f..b8b2ff1beb 100644 --- a/django/core/management/commands/syncdb.py +++ b/django/core/management/commands/syncdb.py @@ -21,7 +21,7 @@ class Command(NoArgsCommand): def handle_noargs(self, **options): from django.db import connection, transaction, models from django.conf import settings - from django.core.management.sql import table_list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal + from django.core.management.sql import table_names, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive') @@ -45,7 +45,7 @@ class Command(NoArgsCommand): table_name_converter = lambda x: x # Get a list of all existing database tables, so we know what needs to # be added. - tables = [table_name_converter(name) for name in table_list()] + tables = [table_name_converter(name) for name in table_names()] # Get a list of already installed *models* so that references work right. seen_models = installed_models(tables) diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 1ccb100361..574be5a1ee 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -7,13 +7,13 @@ try: except NameError: from sets import Set as set # Python 2.3 fallback -def table_list(): +def table_names(): "Returns a list of all table names that exist in the database." from django.db import connection, get_introspection_module cursor = connection.cursor() - return get_introspection_module().get_table_list(cursor) + return set(get_introspection_module().get_table_list(cursor)) -def django_table_list(only_existing=False): +def django_table_names(only_existing=False): """ Returns a list of all table names that have associated Django models and are in INSTALLED_APPS. @@ -22,14 +22,13 @@ def django_table_list(only_existing=False): that actually exist in the database. """ from django.db import models - tables = [] + tables = set() for app in models.get_apps(): for model in models.get_models(app): - tables.append(model._meta.db_table) - tables.extend([f.m2m_db_table() for f in model._meta.local_many_to_many]) + tables.add(model._meta.db_table) + tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many]) if only_existing: - existing = table_list() - tables = [t for t in tables if t in existing] + tables = [t for t in tables if t in table_names()] return tables def installed_models(table_list): @@ -82,7 +81,7 @@ def sql_create(app, style): # we can be conservative). app_models = models.get_models(app) final_output = [] - known_models = set([model for model in installed_models(table_list()) if model not in app_models]) + known_models = set([model for model in installed_models(table_names()) if model not in app_models]) pending_references = {} for model in app_models: @@ -214,9 +213,9 @@ def sql_flush(style, only_django=False): """ from django.db import connection if only_django: - tables = django_table_list() + tables = django_table_names() else: - tables = table_list() + tables = table_names() statements = connection.ops.sql_flush(style, tables, sequence_list()) return statements