From ada13cb826498c2912a29000d45734849027be8f Mon Sep 17 00:00:00 2001 From: Tyndie Date: Thu, 8 Jun 2017 12:49:51 +0100 Subject: [PATCH] Initial Django 1.11 fixes - Add optional name parameter to create_cursor in base.py to allow for name variable being passed in base backend _cursor method. - Add DatabaseWrapper class attributes to base.py required in Django 1.11 base backend. - Moved unneeded inline import for ImproperlyConfigured exception to top of base.py. TODO: - Isolation levels. - Simplified timezone handling. --- lib/mysql/connector/django/base.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/mysql/connector/django/base.py b/lib/mysql/connector/django/base.py index 7ffc222..078c81b 100644 --- a/lib/mysql/connector/django/base.py +++ b/lib/mysql/connector/django/base.py @@ -22,6 +22,7 @@ import warnings import django +from django.core.exceptions import ImproperlyConfigured from django.utils.functional import cached_property try: @@ -29,7 +30,6 @@ from mysql.connector.conversion import MySQLConverter, MySQLConverterBase from mysql.connector.catch23 import PY2 except ImportError as err: - from django.core.exceptions import ImproperlyConfigured raise ImproperlyConfigured( "Error loading mysql.connector module: {0}".format(err)) @@ -332,6 +332,15 @@ def data_types(self): SchemaEditorClass = DatabaseSchemaEditor Database = mysql.connector + if django.VERSION >= (1, 11): + # Classes instantiated in __init__(). + client_class = DatabaseClient + creation_class = DatabaseCreation + features_class = DatabaseFeatures + introspection_class = DatabaseIntrospection + ops_class = DatabaseOperations + validation_class = DatabaseValidation + def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) @@ -344,12 +353,13 @@ def __init__(self, *args, **kwargs): self.converter = DjangoCMySQLConverter() else: self.converter = DjangoMySQLConverter() - self.ops = DatabaseOperations(self) - self.features = DatabaseFeatures(self) - self.client = DatabaseClient(self) - self.creation = DatabaseCreation(self) - self.introspection = DatabaseIntrospection(self) - self.validation = DatabaseValidation(self) + if django.VERSION < (1, 11): + self.ops = DatabaseOperations(self) + self.features = DatabaseFeatures(self) + self.client = DatabaseClient(self) + self.creation = DatabaseCreation(self) + self.introspection = DatabaseIntrospection(self) + self.validation = DatabaseValidation(self) def _valid_connection(self): if self.connection: @@ -418,7 +428,7 @@ def init_connection_state(self): except AttributeError: self._set_autocommit(self.settings_dict['AUTOCOMMIT']) - def create_cursor(self): + def create_cursor(self, name=None): # Django 1.6 cursor = self.connection.cursor() return CursorWrapper(cursor)