Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#618 closed defect (fixed)

[patch] (reopened) Support for non-standard database port

Reported by: Esaj Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This patch adds support for non-standard database ports, by specifying DATABASE_PORT. Tested with PostgreSQL, but not with MySQL.

Attachments (1)

database_port.patch (3.1 KB ) - added by Esaj 19 years ago.

Download all attachments as: .zip

Change History (9)

by Esaj, 19 years ago

Attachment: database_port.patch added

comment:1 by ian@…, 19 years ago

Hi.
I tried your patch on mysql, and it was complaining about wanting an integer and not a string for a port.
by placing DATABASE_PORT=3306 (which is the default) in global_settings.py it stopped complaining.

comment:2 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [858]) Fixed #618 -- Added DATABASE_PORT setting. Thanks, Esaj

comment:3 by wmealing@…, 18 years ago

For others who might be seeing this problem.

python manage.py init
Error: The database couldn't be initialized.
an integer is required

settings.py should have

DATABASE_PORT = 3306 <-- note the integer

not

DATABASE_PORT = '3306' <-- note the quotes.

comment:4 by matt, 18 years ago

Resolution: fixed
Status: closedreopened

I think that we should be setting this as a string in the settings file and converting it to an int for MySQL (this doesn't look like an issue for Postgres and it has not been implemented in MSSQL). All of the other database settings are strings and we ship the settings file with DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.

Here are two quick patches to take care of this:

magic-removal:

Index: django/core/db/backends/mysql.py
===================================================================
--- django/core/db/backends/mysql.py	(revision 2475)
+++ django/core/db/backends/mysql.py	(working copy)
@@ -63,7 +63,7 @@
                 'conv': django_conversions,
             }
             if DATABASE_PORT:
-                kwargs['port'] = DATABASE_PORT
+                kwargs['port'] = int(DATABASE_PORT)
             self.connection = Database.connect(**kwargs)
         cursor = self.connection.cursor()
         if self.connection.get_server_info() >= '4.1':

Trunk:

Index: django/db/backends/mysql/base.py
===================================================================
--- django/db/backends/mysql/base.py	(revision 2475)
+++ django/db/backends/mysql/base.py	(working copy)
@@ -62,7 +62,7 @@
                 'conv': django_conversions,
             }
             if settings.DATABASE_PORT:
-                kwargs['port'] = settings.DATABASE_PORT
+                kwargs['port'] = int(settings.DATABASE_PORT)
             self.connection = Database.connect(**kwargs)
         cursor = self.connection.cursor()
         if self.connection.get_server_info() >= '4.1':

comment:5 by matt , 18 years ago

Summary: Support for non-standard database port[patch] (reopened) Support for non-standard database port

changed summary.

comment:6 by eugene@…, 18 years ago

I think Matt mistyped his patches: 1st patch should be applied to the trunk, and 2nd patch is for magic-removal.

comment:7 by matt, 18 years ago

Eugene is correct, sorry about that.

comment:8 by Jacob, 18 years ago

Resolution: fixed
Status: reopenedclosed

(In [2614]) magic-removal: fixed #618 -- the mysql backend now tolerates strings in DATABASE_PORT

Note: See TracTickets for help on using tickets.
Back to Top