mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
[soc2009/multidb] Fixed a bug with EmptyQuerySet.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11257 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
24b66ace9d
commit
6060ee7c77
@ -2,6 +2,7 @@ from optparse import make_option
|
|||||||
|
|
||||||
from django.core.management.base import LabelCommand
|
from django.core.management.base import LabelCommand
|
||||||
from django.db import connections, transaction, models, DEFAULT_DB_ALIAS
|
from django.db import connections, transaction, models, DEFAULT_DB_ALIAS
|
||||||
|
from django.db.utils import call_with_connection
|
||||||
|
|
||||||
class Command(LabelCommand):
|
class Command(LabelCommand):
|
||||||
help = "Creates the table needed to use the SQL cache backend."
|
help = "Creates the table needed to use the SQL cache backend."
|
||||||
@ -30,7 +31,7 @@ class Command(LabelCommand):
|
|||||||
index_output = []
|
index_output = []
|
||||||
qn = connection.ops.quote_name
|
qn = connection.ops.quote_name
|
||||||
for f in fields:
|
for f in fields:
|
||||||
field_output = [qn(f.name), f.db_type(connection)]
|
field_output = [qn(f.name), call_with_connection(f.db_type, connection=connection)]
|
||||||
field_output.append("%sNULL" % (not f.null and "NOT " or ""))
|
field_output.append("%sNULL" % (not f.null and "NOT " or ""))
|
||||||
if f.primary_key:
|
if f.primary_key:
|
||||||
field_output.append("PRIMARY KEY")
|
field_output.append("PRIMARY KEY")
|
||||||
|
@ -8,6 +8,7 @@ except NameError:
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
from django.db.utils import call_with_connection
|
||||||
|
|
||||||
# The prefix to put on the default database name when creating
|
# The prefix to put on the default database name when creating
|
||||||
# the test database.
|
# the test database.
|
||||||
@ -47,7 +48,7 @@ class BaseDatabaseCreation(object):
|
|||||||
pending_references = {}
|
pending_references = {}
|
||||||
qn = self.connection.ops.quote_name
|
qn = self.connection.ops.quote_name
|
||||||
for f in opts.local_fields:
|
for f in opts.local_fields:
|
||||||
col_type = f.db_type(self.connection)
|
col_type = call_with_connection(f.db_type, connection=self.connection)
|
||||||
tablespace = f.db_tablespace or opts.db_tablespace
|
tablespace = f.db_tablespace or opts.db_tablespace
|
||||||
if col_type is None:
|
if col_type is None:
|
||||||
# Skip ManyToManyFields, because they're not represented as
|
# Skip ManyToManyFields, because they're not represented as
|
||||||
|
@ -5,6 +5,7 @@ from django.db.models.fields import AutoField, Field, IntegerField, PositiveInte
|
|||||||
from django.db.models.related import RelatedObject
|
from django.db.models.related import RelatedObject
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.db.models.query_utils import QueryWrapper
|
from django.db.models.query_utils import QueryWrapper
|
||||||
|
from django.db.utils import call_with_connection
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _
|
from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
@ -772,7 +773,7 @@ class ForeignKey(RelatedField, Field):
|
|||||||
isinstance(rel_field, (PositiveIntegerField,
|
isinstance(rel_field, (PositiveIntegerField,
|
||||||
PositiveSmallIntegerField)))):
|
PositiveSmallIntegerField)))):
|
||||||
return IntegerField().db_type(connection)
|
return IntegerField().db_type(connection)
|
||||||
return rel_field.db_type(connection)
|
return call_with_connection(rel_field.db_type, connection=connection)
|
||||||
|
|
||||||
class OneToOneField(ForeignKey):
|
class OneToOneField(ForeignKey):
|
||||||
"""
|
"""
|
||||||
|
@ -33,7 +33,12 @@ class QuerySet(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, model=None, query=None):
|
def __init__(self, model=None, query=None):
|
||||||
self.model = model
|
self.model = model
|
||||||
using = model._meta.using or DEFAULT_DB_ALIAS
|
# EmptyQuerySet instantiates QuerySet with model as None
|
||||||
|
if model:
|
||||||
|
using = model._meta.using
|
||||||
|
else:
|
||||||
|
using = None
|
||||||
|
using = using or DEFAULT_DB_ALIAS
|
||||||
connection = connections[using]
|
connection = connections[using]
|
||||||
self.query = query or sql.Query(self.model, connection)
|
self.query = query or sql.Query(self.model, connection)
|
||||||
self._result_cache = None
|
self._result_cache = None
|
||||||
|
@ -6,6 +6,7 @@ import datetime
|
|||||||
from django.utils import tree
|
from django.utils import tree
|
||||||
from django.db.models.fields import Field
|
from django.db.models.fields import Field
|
||||||
from django.db.models.query_utils import QueryWrapper
|
from django.db.models.query_utils import QueryWrapper
|
||||||
|
from django.db.utils import call_with_connection
|
||||||
from datastructures import EmptyResultSet, FullResultSet
|
from datastructures import EmptyResultSet, FullResultSet
|
||||||
|
|
||||||
# Connection types
|
# Connection types
|
||||||
@ -266,7 +267,7 @@ class Constraint(object):
|
|||||||
try:
|
try:
|
||||||
if self.field:
|
if self.field:
|
||||||
params = self.field.get_db_prep_lookup(lookup_type, value)
|
params = self.field.get_db_prep_lookup(lookup_type, value)
|
||||||
db_type = self.field.db_type(connection)
|
db_type = call_with_connection(self.field.db_type, connection=connection)
|
||||||
else:
|
else:
|
||||||
# This branch is used at times when we add a comparison to NULL
|
# This branch is used at times when we add a comparison to NULL
|
||||||
# (we don't really want to waste time looking up the associated
|
# (we don't really want to waste time looking up the associated
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -31,6 +32,13 @@ def load_backend(backend_name):
|
|||||||
else:
|
else:
|
||||||
raise # If there's some other error, this must be an error in Django itself.
|
raise # If there's some other error, this must be an error in Django itself.
|
||||||
|
|
||||||
|
def call_with_connection(func, *args, **kwargs):
|
||||||
|
arg_names, varargs, varkwargs, defaults = inspect.getargspec(func)
|
||||||
|
if 'connection' not in arg_names and varkwargs is None:
|
||||||
|
del kwargs['connection']
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ConnectionHandler(object):
|
class ConnectionHandler(object):
|
||||||
def __init__(self, databases):
|
def __init__(self, databases):
|
||||||
self.databases = databases
|
self.databases = databases
|
||||||
|
Loading…
x
Reference in New Issue
Block a user