Re: [Django] #33685: Support using service names for tests on PostgreSQL.

8 views
Skip to first unread message

Django

unread,
May 16, 2022, 3:33:10 AM5/16/22
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"647480166bfe7532e8c471fef0146e3a17e6c0c9" 64748016]:
{{{
#!CommitTicketReference repository=""
revision="647480166bfe7532e8c471fef0146e3a17e6c0c9"
Refs #33685 -- Doc'd that using PostgreSQL's service names for testing
purposes is not supported.
}}}

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

Django

unread,
May 16, 2022, 3:34:10 AM5/16/22
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"de9c08c0f3d79aba7fafbc5d8dea879d1fc5c5ca" de9c08c0]:
{{{
#!CommitTicketReference repository=""
revision="de9c08c0f3d79aba7fafbc5d8dea879d1fc5c5ca"
[4.0.x] Refs #33685 -- Doc'd that using PostgreSQL's service names for


testing purposes is not supported.

Backport of 647480166bfe7532e8c471fef0146e3a17e6c0c9 from main
}}}

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

Django

unread,
Nov 13, 2022, 10:03:33 AM11/13/22
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Joshua Lusk):

Was messing around with this and found the immediate issue to be that the
`.pop()` call in `get_connection_params()` was destructive to
`self.settings_dict`, since assigning `settings_dict = self.settings_dict`
means both still reference the same underlying dictionary. This means that
after `_nodb_cursor` is done creating the test database, acquiring the
normal cursor will fail since `['OPTIONS']['service']` has been removed
from `[OPTIONS]` entirely. I was able to get tests to work by removing the
destructive call to `.pop()` and specifying service as `None` specifically
in the `conn_params` for this case:

{{{#!diff
diff --git a/django/db/backends/postgresql/base.py
b/django/db/backends/postgresql/base.py
index 2758c402ab..be1c05f313 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -194,8 +194,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
}
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"]}
+ conn_params = {"database": "postgres", "service": None,
**settings_dict["OPTIONS"]}
else:
conn_params = {**settings_dict["OPTIONS"]}

}}}

But to [https://code.djangoproject.com/ticket/33685#comment:13 Mariusz
Felisiak]'s point:

> I've tried to implement this but all mechanism related with
creating/cloning test databases are based on the database name. It's
feasible, however, my draft patch is quite complex and the risk of
introducing regressions in a stable version is too great, IMO. I'd
document that service names cannot be currently used for testing purposes
and treat this as a new feature request.

There might be more to this than meets the eye, especially if their are
code paths other than the instance of `DatabaseWrapper` created by
`_nodb_cursor` that use this branch of `get_connection_params()` that I am
not aware of.

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

Django

unread,
11:20 AM (12 hours ago) 11:20 AM
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: Pravin
Type: New feature | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Pravin):

* has_patch: 0 => 1
* owner: nobody => Pravin
* status: new => assigned

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

Django

unread,
11:34 AM (12 hours ago) 11:34 AM
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: Pravin
Type: New feature | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Pravin):

* has_patch: 1 => 0

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

Django

unread,
11:39 AM (12 hours ago) 11:39 AM
to django-...@googlegroups.com
#33685: Support using service names for tests on PostgreSQL.
-----------------------------------+------------------------------------
Reporter: Shane Ambler | Owner: Pravin
Type: New feature | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Pravin):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/33685#comment:21>
Reply all
Reply to author
Forward
0 new messages