#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 <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/010701847184557b-18098810-bbab-45ea-88dd-3f9a8766c847-000000%40eu-central-1.amazonses.com.