Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #305 (closed task: fixed)

Opened 14 years ago

Last modified 12 years ago

SQLObject doesn't correctly handle certain DSN strings

Reported by: cliff@… Owned by: jorge.vargas
Priority: normal Milestone: 1.0b2
Component: Documentation Version:
Severity: normal Keywords:
Cc:

Description

It doesn't appear easy to specify a unix domain socket with SQLObject unless it happens to lie in the default location (/tmp/pgsql.port). The easy workaround is to just pass the connection info as named arguments, but then SQLObject complains of multiple values for named parameters getting passed. Easy workaround (doesn't address possible bugs in DSN parsing code) is to modify sqlobject/postgres/pgconnection.py. In the method connectionFromURI(), simply update the parsed arguments with named arguments rather than adding them:

def connectionFromURI(cls, uri):

user, password, host, port, path, args = cls._parseURI(uri) path = path.strip('/') kwargs = { 'host': host,

'port': port, 'db': path, 'user': user, 'passwd': password }

kwargs.update(args) return cls(kwargs)

connectionFromURI = classmethod(connectionFromURI)

This lets the user override defaults (and work around bugs) without too much fuss and without breaking existing code. With this modification I'm able to use

sqlobject.dburi="postgres:///?host=/var/www/virtual/hostname.com/pgdata/&db=databasename"

Change History

comment:1 Changed 14 years ago by cliff@…

Sorry, here's the formatted code:

    def connectionFromURI(cls, uri):
        user, password, host, port, path, args = cls._parseURI(uri)
        path = path.strip('/')
        kwargs = { 'host': host,
                   'port': port,
                   'db': path,
                   'user': user,
                   'passwd': password }
        kwargs.update(args)
        return cls(**kwargs)
    connectionFromURI = classmethod(connectionFromURI)

comment:2 Changed 13 years ago by matthew@…

I'd imagine anyone running on Ubuntu using Postgres will hit this too, unless I'm missing something. By default, postgresq listens on /var/run/postgresql. The change to pgconnection.py above works for me, though passing those named arguments is a little unwieldy.

comment:3 Changed 13 years ago by jorge.vargas

  • Owner changed from anonymous to jorge.vargas
  • Status changed from new to assigned
  • Type changed from defect to task
  • Component changed from SQLObject to Docs
  • Milestone set to 1.0b1

from SQLObject mailing list

To specify a unix domain socket with SQLObject use the syntax:

postgres:///var/run/postgresql/test?debug=1

For MySQL it is "unix_socket" argument:

mysql://localhost/database?unix_socket=/var/lib/mysql/socket

TODO document this feature.

comment:4 Changed 13 years ago by khorn

  • Milestone changed from 1.0b1 to 1.0b2

milestone passed, changing to 1.0b2

comment:5 Changed 13 years ago by ajones

Probably could port and do some minor editing of this trac page:

http://trac.turbogears.org/turbogears/wiki/SockFile

comment:6 Changed 13 years ago by jorge.vargas

  • Status changed from assigned to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.