Code

Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#618 closed defect (fixed)

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

Reported by: Esaj Owned by: adrian
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: UI/UX:

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 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by Esaj

comment:1 Changed 9 years ago by ian@…

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 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:3 Changed 8 years ago by wmealing@…

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 Changed 8 years ago by matt

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 Changed 8 years ago by matt

  • Summary changed from Support for non-standard database port to [patch] (reopened) Support for non-standard database port

changed summary.

comment:6 Changed 8 years ago by eugene@…

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

comment:7 Changed 8 years ago by matt

Eugene is correct, sorry about that.

comment:8 Changed 8 years ago by jacob

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.