diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-05-10 12:55:30 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-05-10 12:55:30 +0100 |
| commit | cb4b0de49e027f09f8abe63e2fa43f60fc1ef13f (patch) | |
| tree | 712da07b2b80fc503aea683c096a8774dceaad01 /django/db | |
| parent | f6801a234fb9460eac80d146534ac340e178c466 (diff) | |
| parent | bdd285723f9b0044eca690634c412c1c3eec76c0 (diff) | |
Merge branch 'master' into schema-alteration
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/backends/mysql/base.py | 21 | ||||
| -rw-r--r-- | django/db/backends/mysql/validation.py | 3 | ||||
| -rw-r--r-- | django/db/models/__init__.py | 3 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 15 | ||||
| -rw-r--r-- | django/db/models/query.py | 6 | ||||
| -rw-r--r-- | django/db/models/query_utils.py | 5 | ||||
| -rw-r--r-- | django/db/models/sql/compiler.py | 2 | ||||
| -rw-r--r-- | django/db/utils.py | 2 |
8 files changed, 27 insertions, 30 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 90f5018f8b..fd9655077e 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -30,6 +30,11 @@ if (version < (1, 2, 1) or (version[:3] == (1, 2, 1) and from MySQLdb.converters import conversions, Thing2Literal from MySQLdb.constants import FIELD_TYPE, CLIENT +try: + import pytz +except ImportError: + pytz = None + from django.conf import settings from django.db import utils from django.db.backends import * @@ -123,7 +128,7 @@ class CursorWrapper(object): except Database.OperationalError as e: # Map some error codes to IntegrityError, since they seem to be # misclassified and Django would prefer the more logical place. - if e[0] in self.codes_for_integrityerror: + if e.args[0] in self.codes_for_integrityerror: six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) raise @@ -133,7 +138,7 @@ class CursorWrapper(object): except Database.OperationalError as e: # Map some error codes to IntegrityError, since they seem to be # misclassified and Django would prefer the more logical place. - if e[0] in self.codes_for_integrityerror: + if e.args[0] in self.codes_for_integrityerror: six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) raise @@ -190,6 +195,15 @@ class DatabaseFeatures(BaseDatabaseFeatures): @cached_property def has_zoneinfo_database(self): + # MySQL accepts full time zones names (eg. Africa/Nairobi) but rejects + # abbreviations (eg. EAT). When pytz isn't installed and the current + # time zone is LocalTimezone (the only sensible value in this + # context), the current time zone name will be an abbreviation. As a + # consequence, MySQL cannot perform time zone conversions reliably. + if pytz is None: + return False + + # Test if the time zone definitions are installed. cursor = self.connection.cursor() cursor.execute("SELECT 1 FROM mysql.time_zone LIMIT 1") return cursor.fetchone() is not None @@ -395,8 +409,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): kwargs = { 'conv': django_conversions, 'charset': 'utf8', - 'use_unicode': True, } + if not six.PY3: + kwargs['use_unicode'] = True settings_dict = self.settings_dict if settings_dict['USER']: kwargs['user'] = settings_dict['USER'] diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py index de7474d1e5..2ce957cce7 100644 --- a/django/db/backends/mysql/validation.py +++ b/django/db/backends/mysql/validation.py @@ -10,6 +10,7 @@ class DatabaseValidation(BaseDatabaseValidation): from django.db import models varchar_fields = (models.CharField, models.CommaSeparatedIntegerField, models.SlugField) - if isinstance(f, varchar_fields) and f.max_length > 255 and f.unique: + if (isinstance(f, varchar_fields) and f.unique + and (f.max_length is None or int(f.max_length) > 255)): msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__}) diff --git a/django/db/models/__init__.py b/django/db/models/__init__.py index 6c5ccd4bd2..5f17229753 100644 --- a/django/db/models/__init__.py +++ b/django/db/models/__init__.py @@ -1,3 +1,5 @@ +from functools import wraps + from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models from django.db.models.query import Q @@ -11,7 +13,6 @@ from django.db.models.fields.files import FileField, ImageField from django.db.models.fields.related import ForeignKey, ForeignObject, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel from django.db.models.deletion import CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError from django.db.models import signals -from django.utils.decorators import wraps def permalink(func): diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index c30ba03489..37fa8b1027 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -204,9 +204,6 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri return rel_obj def __set__(self, instance, value): - if instance is None: - raise AttributeError("%s must be accessed via instance" % self.related.opts.object_name) - # The similarity of the code below to the code in # ReverseSingleRelatedObjectDescriptor is annoying, but there's a bunch # of small differences that would make a common base class convoluted. @@ -310,9 +307,6 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec return rel_obj def __set__(self, instance, value): - if instance is None: - raise AttributeError("%s must be accessed via instance" % self.field.name) - # If null=True, we can assign null here, but otherwise the value needs # to be an instance of the related class. if value is None and self.field.null == False: @@ -382,9 +376,6 @@ class ForeignRelatedObjectsDescriptor(object): return self.related_manager_cls(instance) def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - manager = self.__get__(instance) # If the foreign key can support nulls, then completely clear the related set. # Otherwise, just move the named objects into the set. @@ -765,9 +756,6 @@ class ManyRelatedObjectsDescriptor(object): return manager def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - if not self.related.field.rel.through._meta.auto_created: opts = self.related.field.rel.through._meta raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name)) @@ -822,9 +810,6 @@ class ReverseManyRelatedObjectsDescriptor(object): return manager def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - if not self.field.rel.through._meta.auto_created: opts = self.field.rel.through._meta raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name)) diff --git a/django/db/models/query.py b/django/db/models/query.py index c36d81cc31..337049e2ff 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -312,11 +312,7 @@ class QuerySet(object): if skip: obj = model_cls(**dict(zip(init_list, row_data))) else: - try: - obj = model(*row_data) - except IndexError: - import ipdb; ipdb.set_trace() - pass + obj = model(*row_data) # Store the source database of the object obj._state.db = db diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index a33c44833c..ee7a56a26c 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -102,7 +102,7 @@ class DeferredAttribute(object): f = [f for f in opts.fields if f.attname == self.field_name][0] name = f.name - # Lets see if the field is part of the parent chain. If so we + # Let's see if the field is part of the parent chain. If so we # might be able to reuse the already loaded value. Refs #18343. val = self._check_parent_chain(instance, name) if val is None: @@ -194,8 +194,7 @@ def deferred_class_factory(model, attrs): name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs)))) name = util.truncate_name(name, 80, 32) - overrides = dict([(attr, DeferredAttribute(attr, model)) - for attr in attrs]) + overrides = dict((attr, DeferredAttribute(attr, model)) for attr in attrs) overrides["Meta"] = Meta overrides["__module__"] = model.__module__ overrides["_deferred"] = True diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 3444b74ac3..018fc098ea 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1092,7 +1092,7 @@ class SQLDateTimeCompiler(SQLCompiler): if datetime is None: raise ValueError("Database returned an invalid value " "in QuerySet.dates(). Are time zone " - "definitions installed?") + "definitions and pytz installed?") datetime = datetime.replace(tzinfo=None) datetime = timezone.make_aware(datetime, self.query.tzinfo) yield datetime diff --git a/django/db/utils.py b/django/db/utils.py index 936b42039d..e84060f9b3 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -169,7 +169,7 @@ class ConnectionHandler(object): conn.setdefault('ENGINE', 'django.db.backends.dummy') if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']: conn['ENGINE'] = 'django.db.backends.dummy' - conn.setdefault('CONN_MAX_AGE', 600) + conn.setdefault('CONN_MAX_AGE', 0) conn.setdefault('OPTIONS', {}) conn.setdefault('TIME_ZONE', 'UTC' if settings.USE_TZ else settings.TIME_ZONE) for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']: |
