#32292: Allow postgresql database connections to use postgres services
-------------------------------------+-------------------------------------
Reporter: levihb | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: database postgresql | Triage Stage: Accepted
postgres service pg_service |
config |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by levihb):
Replying to [comment:4 Mariusz Felisiak]:
> Configuration without `NAME` already works for me, e.g.:
> {{{
> 'default': {
> 'ENGINE': 'django.db.backends.postgresql',
> 'OPTIONS': {
> 'service': 'default_django_test'
> }
> },
> }}}
It doesn't work for me. E.g.:
{{{#!python
'default': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {
'service': 'test_service'
}
},
}}}
Throws the following when it tries to access the database:
{{{
Traceback (most recent call last):
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/redacted_path/postgres_services/mysite/testapp/views.py", line 9,
in index
c = db_conn.cursor()
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/db/backends/base/base.py", line 199, in connect
conn_params = self.get_connection_params()
File "/redacted_path/postgres_services/venv/lib/python3.8/site-
packages/django/db/backends/postgresql/base.py", line 157, in
get_connection_params
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is
improperly configured. Please supply the NAME value.
}}}
While if I just add the NAME value it works just fine. This makes total
sense as if you check the postgres base file it checks:
{{{#!python
if settings_dict['NAME'] == '':
raise ImproperlyConfigured(
"settings.DATABASES is improperly configured. "
"Please supply the NAME value.")
if len(settings_dict['NAME'] or '') > self.ops.max_name_length():
raise ImproperlyConfigured(
"The database name '%s' (%d characters) is longer than "
"PostgreSQL's limit of %d characters. Supply a shorter NAME "
"in settings.DATABASES." % (
settings_dict['NAME'],
len(settings_dict['NAME']),
self.ops.max_name_length(),
)
)
}}}
The first if evaluates to true. `settings_dict['NAME']` must be getting
defaulted to an empty string, because I'm not setting it to empty, I'm
entirely leaving it out.
> so only setting `PGSERVICE` for
[https://github.com/django/django/blob/2a76f4313423a3b91caade4fce71790630ef9152/django/db/backends/postgresql/client.py#L10-L44
the underlying command-line client] and docs are missing.
I don't mind adding support for those either.
> > I don't mind creating a pull request for it, but would like to know
why it hasn't been added, ...
>
> Because you're the first to suggest it.
Oh I was sure I wouldn't have been. I've looked up how to use postgres
services for many projects, and nearly always find people asking, even
when it's for much much smaller projects. That's rather interesting.
--
Ticket URL: <https://code.djangoproject.com/ticket/32292#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.25218469bf2395d71f2e68437df53ead%40djangoproject.com.