mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #32732 -- Removed usage of deprecated 'db' and 'passwd' connection options in MySQL backend.
The 'db' and 'passwd' connection options have been deprecated, use 'database' and 'password' instead (available since mysqlclient >= 1.3.8). This also allows the 'database' option in DATABASES['OPTIONS'] on MySQL.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							d06c5b3581
						
					
				
				
					commit
					1061f52436
				
			| @@ -200,9 +200,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): | ||||
|         if settings_dict['USER']: | ||||
|             kwargs['user'] = settings_dict['USER'] | ||||
|         if settings_dict['NAME']: | ||||
|             kwargs['db'] = settings_dict['NAME'] | ||||
|             kwargs['database'] = settings_dict['NAME'] | ||||
|         if settings_dict['PASSWORD']: | ||||
|             kwargs['passwd'] = settings_dict['PASSWORD'] | ||||
|             kwargs['password'] = settings_dict['PASSWORD'] | ||||
|         if settings_dict['HOST'].startswith('/'): | ||||
|             kwargs['unix_socket'] = settings_dict['HOST'] | ||||
|         elif settings_dict['HOST']: | ||||
|   | ||||
| @@ -8,7 +8,10 @@ class DatabaseClient(BaseDatabaseClient): | ||||
|     def settings_to_cmd_args_env(cls, settings_dict, parameters): | ||||
|         args = [cls.executable_name] | ||||
|         env = None | ||||
|         db = settings_dict['OPTIONS'].get('db', settings_dict['NAME']) | ||||
|         database = settings_dict['OPTIONS'].get( | ||||
|             'database', | ||||
|             settings_dict['OPTIONS'].get('db', settings_dict['NAME']), | ||||
|         ) | ||||
|         user = settings_dict['OPTIONS'].get('user', settings_dict['USER']) | ||||
|         password = settings_dict['OPTIONS'].get( | ||||
|             'password', | ||||
| @@ -51,7 +54,7 @@ class DatabaseClient(BaseDatabaseClient): | ||||
|             args += ["--ssl-key=%s" % client_key] | ||||
|         if charset: | ||||
|             args += ['--default-character-set=%s' % charset] | ||||
|         if db: | ||||
|             args += [db] | ||||
|         if database: | ||||
|             args += [database] | ||||
|         args.extend(parameters) | ||||
|         return args, env | ||||
|   | ||||
| @@ -9,4 +9,4 @@ Django 3.2.3 fixes several bugs in 3.2.2. | ||||
| Bugfixes | ||||
| ======== | ||||
|  | ||||
| * ... | ||||
| * Prepared for ``mysqlclient`` > 2.0.3 support (:ticket:`32732`). | ||||
|   | ||||
| @@ -50,6 +50,9 @@ class MySqlDbshellCommandTestCase(SimpleTestCase): | ||||
|             'optiondbname', | ||||
|         ] | ||||
|         expected_env = {'MYSQL_PWD': 'optionpassword'} | ||||
|         for keys in [('database', 'password'), ('db', 'passwd')]: | ||||
|             with self.subTest(keys=keys): | ||||
|                 database, password = keys | ||||
|                 self.assertEqual( | ||||
|                     self.settings_to_cmd_args_env({ | ||||
|                         'NAME': 'settingdbname', | ||||
| @@ -58,9 +61,9 @@ class MySqlDbshellCommandTestCase(SimpleTestCase): | ||||
|                         'HOST': 'settinghost', | ||||
|                         'PORT': settings_port, | ||||
|                         'OPTIONS': { | ||||
|                     'db': 'optiondbname', | ||||
|                             database: 'optiondbname', | ||||
|                             'user': 'optionuser', | ||||
|                     'passwd': 'optionpassword', | ||||
|                             password: 'optionpassword', | ||||
|                             'host': 'optionhost', | ||||
|                             'port': options_port, | ||||
|                         }, | ||||
| @@ -68,23 +71,28 @@ class MySqlDbshellCommandTestCase(SimpleTestCase): | ||||
|                     (expected_args, expected_env), | ||||
|                 ) | ||||
|  | ||||
|     def test_options_password(self): | ||||
|     def test_options_non_deprecated_keys_preferred(self): | ||||
|         expected_args = [ | ||||
|             'mysql', | ||||
|             '--user=someuser', | ||||
|             '--host=somehost', | ||||
|             '--port=444', | ||||
|             'somedbname', | ||||
|             'optiondbname', | ||||
|         ] | ||||
|         expected_env = {'MYSQL_PWD': 'optionpassword'} | ||||
|         self.assertEqual( | ||||
|             self.settings_to_cmd_args_env({ | ||||
|                 'NAME': 'somedbname', | ||||
|                 'NAME': 'settingdbname', | ||||
|                 'USER': 'someuser', | ||||
|                 'PASSWORD': 'settingpassword', | ||||
|                 'HOST': 'somehost', | ||||
|                 'PORT': 444, | ||||
|                 'OPTIONS': {'password': 'optionpassword'}, | ||||
|                 'OPTIONS': { | ||||
|                     'database': 'optiondbname', | ||||
|                     'db': 'deprecatedoptiondbname', | ||||
|                     'password': 'optionpassword', | ||||
|                     'passwd': 'deprecatedoptionpassword', | ||||
|                 }, | ||||
|             }), | ||||
|             (expected_args, expected_env), | ||||
|         ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user