[Django] #33685: Using new postgresql settings fails when running tests

22 views
Skip to first unread message

Django

unread,
May 8, 2022, 3:18:14 AM5/8/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
---------------------------------------------+------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
In django 4.0 the postgresql DATABASE settings were changed to allow use
of a .pg_service.conf and .pgpass file being defined in the OPTIONS value.

Using the **old** config **works** fine in both runserver and test.

Using the **new** config works for runserver but **fails** for test.

In settings I have :-

{{{#!python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {
'service': 'yfsm_pgdb',
'passfile': '.yfsm_pgpass',
},
},
}
}}}

I have the user password entry allowing login to any database (using `*`)
I have also tried adding an entry with `test_dbname`. I also tried adding
an entry in .pg_service.conf as `[test_yfsm_pgdb]`

running tests I see `django.db.utils.OperationalError: fe_sendauth: no
password supplied` indicating that the password file is not used.

It would appear that when testing, the new OPTIONS settings are ignored.

--
Ticket URL: <https://code.djangoproject.com/ticket/33685>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 8, 2022, 3:36:48 AM5/8/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------

Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Shane Ambler):

Looking at the pull request for the OPTIONS change, I find that I can use
the service name `django_test`. This does not appear to be documented
anywhere.

While I wouldn't initially agree with using one login for testing all
projects, use of this pg service name needs to be documented.

--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:1>

Django

unread,
May 8, 2022, 3:38:07 AM5/8/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-------------------------------+--------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 4.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Shane Ambler):

* component: Testing framework => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:2>

Django

unread,
May 8, 2022, 5:25:03 AM5/8/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------

Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Shane Ambler):

* component: Documentation => Testing framework


--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:3>

Django

unread,
May 8, 2022, 5:27:02 AM5/8/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Shane Ambler):

I failed to get my setting file right when I checked that, the use of the
`django_test` service name is part of the django project tests.

The use of postgresql service name still appears broken with testing

--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:4>

Django

unread,
May 9, 2022, 1:10:39 AM5/9/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: closed

Component: Testing framework | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

If you want to user PostgreSQL's password files, all required databases
must be included, i.e. `postgres`, `dbname`, `test_dbname`, e.g. the
following configuration works for me
{{{
localhost:5432:postgres:postgres_username:SeCrEtPassworD
localhost:5432:dbname:postgres_username:SeCrEtPassworD
localhost:5432:test_dbname:postgres_username:SeCrEtPassworD
}}}
`settings.py`:


{{{#!python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',

'HOST': 'localhost',
'PORT': 5432,
'NAME': 'dbname',
'USER': 'postgres_username',
'OPTIONS': {
'passfile': '.custompgpass',
}
},
}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:5>

Django

unread,
May 9, 2022, 10:25:54 PM5/9/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Shane Ambler):

Replying to [comment:5 Mariusz Felisiak]:


> If you want to user PostgreSQL's password files, all required databases
must be included, i.e. `postgres`, `dbname`, `test_dbname`, e.g. the
following configuration works for me
> {{{
> localhost:5432:postgres:postgres_username:SeCrEtPassworD
> localhost:5432:dbname:postgres_username:SeCrEtPassworD
> localhost:5432:test_dbname:postgres_username:SeCrEtPassworD
> }}}

Yes, I tried both the `test_dbname` and `*` to match any dbname and it
still fails.

> `settings.py`:
> {{{#!python
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.postgresql',
> 'HOST': 'localhost',
> 'PORT': 5432,
> 'NAME': 'dbname',
> 'USER': 'postgres_username',
> 'OPTIONS': {
> 'passfile': '.custompgpass',
> }
> },
> }
> }}}

While you are maintaining both old and new config variations, all will
continue to work for you.

If you remove the old, no longer documented, settings of `HOST` `PORT`
`NAME` `USER` then your setup will work for `runserver` but not `test`

The pg docs [https://docs.djangoproject.com/en/4.0/ref/databases
/#postgresql-notes-1] only documents the new method of specifying
`service` and `passfile` in the `OPTIONS` - this documented setup **does
not support running tests** with postgresql databases.

--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:6>

Django

unread,
May 9, 2022, 10:28:48 PM5/9/22
to django-...@googlegroups.com
#33685: Using new postgresql settings fails when running tests
-----------------------------------+--------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Shane Ambler):

* status: closed => new
* resolution: invalid =>


--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:7>

Reply all
Reply to author
Forward
0 new messages