Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed test failures on MySQL.

Some tests failed when the time zone definitions were loaded in MySQL
and pytz wasn't installed. This setup isn't supported.
  • Loading branch information...
commit 1fff8daf889822aa1dd9adba19c94bb522d960b4 1 parent de8aa3a
@aaugustin aaugustin authored
14 django/db/backends/mysql/
@@ -30,6 +30,11 @@
from MySQLdb.converters import conversions, Thing2Literal
from MySQLdb.constants import FIELD_TYPE, CLIENT
+ import pytz
+except ImportError:
+ pytz = None
from django.conf import settings
from django.db import utils
from django.db.backends import *
@@ -186,6 +191,15 @@ def can_introspect_foreign_keys(self):
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
2  django/db/models/sql/
@@ -1092,7 +1092,7 @@ def results_iter(self):
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
3  docs/ref/models/querysets.txt
@@ -627,7 +627,8 @@ object. If it's ``None``, Django uses the :ref:`current time zone
- SQLite: install pytz_ — conversions are actually performed in Python.
- PostgreSQL: no requirements (see `Time Zones`_).
- Oracle: no requirements (see `Choosing a Time Zone File`_).
- - MySQL: load the time zone tables with `mysql_tzinfo_to_sql`_.
+ - MySQL: install pytz_ and load the time zone tables with
+ `mysql_tzinfo_to_sql`_.
.. _pytz:
.. _Time Zones:

0 comments on commit 1fff8da

Please sign in to comment.
Something went wrong with that request. Please try again.