Edgewall Software
Modify

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#8378 closed defect (fixed)

PostgreSQL environment upgrade issue

Reported by: Emmanuel Blot Owned by: Felix Schwarz <felix.schwarz@…>
Priority: normal Milestone: 0.11.5
Component: database backend Version: 0.12dev
Severity: major Keywords: posgresql
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I'm in the process of migrating from SQLite to PostgreSQL DB backend, and I have to upgrade the environment once more to upgrade Bitten.

I ran "trac-admin project" upgrade command and received the following error:

Trac [/local/var/trac/projects/tools]> upgrade
KeyError: 'params'

It ends up to be an issue here:

# trac/db/postgres_backend.py
def backup(self, dest_file):
        # line 114
        if 'host' in db_prop['params']:
            host = db_prop['params']['host']
        else:
            host = db_prop.get('host', 'localhost')

This part of the code does not seems to match the construction of the db_prop dictionary, from trac/db/api.py

def _parse_db_str(db_str):
   # ...
   args = zip(('user', 'password', 'host', 'port', 'path', 'params'),
               (user, password, host, port, path, params))
   return scheme, dict([(key, value) for key, value in args if value])

where params may not be a dictionary entry if no value is tied to params

Here is a quick workaround to bypass the issue, although I'm not sure it's valid (no time to understand the nuts and bolts of this backend for now…)

  • trac/db/postgres_backend.py

     
    111111        args = [self.pg_dump_path, '-C', '-d', '-x', '-Z', '8',
    112112                '-U', db_prop['user'],]
    113113        port = db_prop.get('port', '5432')
    114         if 'host' in db_prop['params']:
    115             host = db_prop['params']['host']
     114        if 'host' in db_prop:
     115            host = db_prop['host']
    116116        else:
    117117            host = db_prop.get('host', 'localhost')
    118118        args.append('-h')
     
    121121            args.append('-p')
    122122            args.append(str(port))
    123123
    124         if 'schema' in db_prop['params']:
    125             args.extend(['-n', db_prop['params']['schema']])
     124        if 'params' in db_prop:
     125            if 'schema' in db_prop['params']:
     126                args.extend(['-n', db_prop['params']['schema']])
    126127
    127128        dest_file += ".gz"
    128129        args.extend(['-f', dest_file, db_name])

Note: it might be nice to have a "DB backend" component to report issues against.

Attachments (1)

psql_backend_does_not_assume_any_properties_8378 (502 bytes ) - added by Felix Schwarz <felix.schwarz@…> 15 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Felix Schwarz <felix.schwarz@…>, 15 years ago

eblot: I think your patch is wrong because it there is there else clause which uses 'host' already. The real problem is that db_propparams could be missing as you already noted.

I'm attaching a preliminary patch for 0.11

by Felix Schwarz <felix.schwarz@…>, 15 years ago

comment:2 by Felix Schwarz <felix.schwarz@…>, 15 years ago

Btw: The same problem exists in 0.11 so please fix the issue on all branches.

comment:3 by Christian Boos, 15 years ago

Milestone: 0.120.11.5

comment:4 by Christian Boos, 15 years ago

Milestone: 0.11.60.11.5

comment:5 by Remy Blank, 15 years ago

Owner: set to Remy Blank

Working on that.

comment:6 by Remy Blank, 15 years ago

Component: generaldatabase backend
Resolution: fixed
Status: newclosed

Felix is right, db_prop['params'] can be missing, and his patch fixes the issue. Applied in [8312], thanks!

The logic for 'host' is correct, and handles the case where the host is specified as an additional parameter, which is useful if you connect to PostgreSQL through a UNIX socket. See DatabaseBackend#Postgresql for more details.

it might be nice to have a "DB backend" component to report issues against.

Wish granted :-)

comment:7 by Remy Blank, 15 years ago

Owner: changed from Remy Blank to Felix Schwarz <felix.schwarz@…>

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Felix Schwarz <felix.schwarz@…>.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Felix Schwarz <felix.schwarz@…> to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.