Edgewall Software
Modify

Ticket #8378 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

PostgreSQL environment upgrade issue

Reported by: eblot Owned by: Felix Schwarz <felix.schwarz@…>
Priority: normal Milestone: 0.11.5
Component: database backend Version: 0.12dev
Severity: major Keywords: posgresql
Cc:
Release Notes:
API 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

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

Download all attachments as: .zip

Change History

comment:1 Changed 3 years ago by Felix Schwarz <felix.schwarz@…>

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

Changed 3 years ago by Felix Schwarz <felix.schwarz@…>

comment:2 Changed 3 years ago by Felix Schwarz <felix.schwarz@…>

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

comment:3 Changed 3 years ago by cboos

  • Milestone changed from 0.12 to 0.11.5

comment:4 Changed 3 years ago by cboos

  • Milestone changed from 0.11.6 to 0.11.5

comment:5 Changed 3 years ago by rblank

  • Owner set to rblank

Working on that.

comment:6 Changed 3 years ago by rblank

  • Component changed from general to database backend
  • Resolution set to fixed
  • Status changed from new to closed

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 Changed 3 years ago by rblank

  • Owner changed from rblank to Felix Schwarz <felix.schwarz@…>
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from Felix Schwarz <felix.schwarz@…>. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.