#491 closed defect (fixed)
Patch to allow non-user PostgreSQL connections.
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm just using the user the application is running as for the database connection, so I use "dbname=whatever" as the psycopg connection string. The PostgreSQL backend requires "user=". The following patch fixes this.
Index: core/db/backends/postgresql.py
===================================================================
--- core/db/backends/postgresql.py (revision 632)
+++ core/db/backends/postgresql.py (working copy)
@@ -17,10 +17,12 @@
def cursor(self):
from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE
_HOST, DATABASE_PASSWORD, DEBUG, TIME_ZONE
if self.connection is None:
- if DATABASE_NAME == or DATABASE_USER == :
+ if DATABASE_NAME == :
from django.core.exceptions import ImproperlyConfigured
- raise ImproperlyConfigured, "You need to specify both DATABASE_
NAME and DATABASE_USER in your Django settings file."
- conn_string = "user=%s dbname=%s" % (DATABASE_USER, DATABASE_NAME)
+ raise ImproperlyConfigured, "You need to specify the DATABASE_N
AME in your Django settings file."
+ conn_string = "dbname=%s" % DATABASE_NAME
+ if DATABASE_USER:
+ conn_string = "user=%s %s" % ( DATABASE_USER, conn_string )
if DATABASE_PASSWORD:
conn_string += " password=%s" % DATABASE_PASSWORD
if DATABASE_HOST:
pgsql-nouser.patch