diff options
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r-- | django/db/backends/postgresql/base.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 9eac005dd1..7926c05c09 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -152,10 +152,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): def get_connection_params(self): settings_dict = self.settings_dict # None may be used to connect to the default 'postgres' db - if settings_dict['NAME'] == '': + if ( + settings_dict['NAME'] == '' and + not settings_dict.get('OPTIONS', {}).get('service') + ): raise ImproperlyConfigured( "settings.DATABASES is improperly configured. " - "Please supply the NAME value.") + "Please supply the NAME or OPTIONS['service'] value." + ) if len(settings_dict['NAME'] or '') > self.ops.max_name_length(): raise ImproperlyConfigured( "The database name '%s' (%d characters) is longer than " @@ -166,10 +170,19 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.ops.max_name_length(), ) ) - conn_params = { - 'database': settings_dict['NAME'] or 'postgres', - **settings_dict['OPTIONS'], - } + conn_params = {} + if settings_dict['NAME']: + conn_params = { + 'database': settings_dict['NAME'], + **settings_dict['OPTIONS'], + } + elif settings_dict['NAME'] is None: + # Connect to the default 'postgres' db. + settings_dict.get('OPTIONS', {}).pop('service', None) + conn_params = {'database': 'postgres', **settings_dict['OPTIONS']} + else: + conn_params = {**settings_dict['OPTIONS']} + conn_params.pop('isolation_level', None) if settings_dict['USER']: conn_params['user'] = settings_dict['USER'] |