diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-09-10 18:58:30 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-09-10 18:58:30 +0000 |
| commit | fcee0c1b66019a0e84bc338e76fa31695d5bd4ca (patch) | |
| tree | 4323649b5df9c56367e11997d6455a941b093b57 /django | |
| parent | 161c6328a0811280926a16275be5ef4164f5866f (diff) | |
Fixed #16809 -- Forced MySQL to behave like a database. This avoids a problem where queries that do IS NONE checks can return the wrong result the first time they are executed if there is a recently inserted row. Thanks to James Pyrich for the debug work and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16785 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index a22951a3b7..e9f5b8b6a9 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -309,7 +309,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): return False def _cursor(self): + new_connection = False if not self._valid_connection(): + new_connection = True kwargs = { 'conv': django_conversions, 'charset': 'utf8', @@ -336,8 +338,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] self.connection.encoders[SafeString] = self.connection.encoders[str] connection_created.send(sender=self.__class__, connection=self) - cursor = CursorWrapper(self.connection.cursor()) - return cursor + cursor = self.connection.cursor() + if new_connection: + # SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column + # on a recently-inserted row will return when the field is tested for + # NULL. Disabling this value brings this aspect of MySQL in line with + # SQL standards. + cursor.execute('SET SQL_AUTO_IS_NULL = 0') + return CursorWrapper(cursor) def _rollback(self): try: |
