Edgewall Software

Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10406 closed defect (fixed)

ERROR: invalid value for parameter "search_path"

Reported by: winix Owned by: Remy Blank
Priority: highest Milestone: 0.12.3
Component: database backend Version: 0.12.2
Severity: critical Keywords: postgresql, schema
Cc: Branch:
Release Notes:
API Changes:


System Information:

  • OS: Archlinux
  • Python: 2.7.2
  • python2-psycopg2 2.4.2
  • Database: postgresql 9.1.1

I run this command to create trac environment:

sudo trac-admin test initenv test 'postgres://user:pass@localhost/trac?schema=test' 'svn' /home/subversion/repos/test

Initenv filed, and python traceback:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/trac/admin/console.py", line 422, in do_initenv
  File "/usr/lib/python2.7/site-packages/trac/env.py", line 213, in __init__
  File "/usr/lib/python2.7/site-packages/trac/env.py", line 401, in create
  File "/usr/lib/python2.7/site-packages/trac/db/api.py", line 146, in init_db
  File "/usr/lib/python2.7/site-packages/trac/db/postgres_backend.py", line 98, in init_db
  File "/usr/lib/python2.7/site-packages/trac/db/postgres_backend.py", line 87, in get_connection
  File "/usr/lib/python2.7/site-packages/trac/db/postgres_backend.py", line 212, in __init__
    cnx.cursor().execute('SET search_path TO %s', (self.schema,))
DataError: invalid value for parameter "search_path": "test"
DETAIL:  schema "test" does not exist

With postgresql 9.1, if schema does not exist, 'SET search_path' will raise DataError, not ProgrammingError (/db/postgres_backend.py)

Attachments (1)

10406-search-path-r10830.patch (878 bytes ) - added by Remy Blank 8 years ago.
Catch the right exception for PostgreSQL 9.1.

Download all attachments as: .zip

Change History (7)

comment:1 by Remy Blank, 8 years ago

Milestone: 0.12.3
Owner: set to Remy Blank
Priority: normalhighest
Severity: normalcritical

Thanks for the report. I don't have a 9.1 server readily available (I should take the time to upgrade my 8.2), but I'll post a patch.

by Remy Blank, 8 years ago

Catch the right exception for PostgreSQL 9.1.

comment:2 by Remy Blank, 8 years ago

Can you please test 10406-search-path-r10830.patch?

To be honest, I don't really understand why we even catch this error. Currently, if SET search_path fails, we leave the search path unchanged, which means that we are going to access the public schema. I think it would be better to abort than to access the wrong schema.

Oh, now I see. It's only to allow a connection to be created for the initial CREATE SCHEMA. This could be done better. Let's see…

comment:3 by Remy Blank, 8 years ago

Mmh… The EnvironmentStub has some weird initialization sequence that actually requires catching the "missing schema" error, so I would rather leave it as-is. So yes, please test the patch above.

comment:4 by winix, 8 years ago

The patch works for me.

I think, before init_db call get_connection function, should remove schema value from params temporary, after get_connection, if schema exists, then create schema and set search_path.

comment:5 by Remy Blank, 8 years ago

Resolution: fixed
Status: newclosed

Thanks for testing. Patch applied in [10831].

About the weird initialization of the connector, we have never had a defect report, so I'd rather leave it as-is at this point. Maybe I'll refactor it on trunk.

comment:6 by Ryan J Ollos, 5 years ago

Keywords: postgresql schema → postgresql, schema

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Remy Blank 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.