Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public schema should not be mandatory #4

Closed
aquilax opened this issue Aug 23, 2011 · 3 comments
Closed

Public schema should not be mandatory #4

aquilax opened this issue Aug 23, 2011 · 3 comments

Comments

@aquilax
Copy link

aquilax commented Aug 23, 2011

aquilax@zelda ~> dbtoyaml -U unity -H 10.10.11.3 -n site unity
Traceback (most recent call last):
  File "/usr/local/bin/dbtoyaml", line 9, in <module>
    load_entry_point('Pyrseas==0.3.0', 'console_scripts', 'dbtoyaml')()
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbtoyaml.py", line 40, in main
    dbmap = db.to_map()
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/database.py", line 116, in to_map
    self.from_catalog()
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/database.py", line 81, in from_catalog
    self.db = self.Dicts(self.dbconn)
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/database.py", line 46, in __init__
    self.languages = LanguageDict(dbconn)
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbobject/__init__.py", line 185, in __init__
    self._from_catalog()
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbobject/__init__.py", line 192, in _from_catalog
    for obj in self.fetch():
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbobject/__init__.py", line 201, in fetch
    self.dbconn.connect()
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbconn.py", line 51, in connect
    self._execute("set search_path to public, pg_catalog")
  File "/usr/local/lib/python2.6/dist-packages/pyrseas/dbconn.py", line 58, in _execute
    curs.execute(query)
  File "/usr/local/lib/python2.6/dist-packages/psycopg2/extras.py", line 121, in execute
    return _cursor.execute(self, query, vars)
psycopg2.ProgrammingError: ('schema "public" does not exist\n', 'set search_path to public, pg_catalog')
@jmafc
Copy link
Member

jmafc commented Aug 23, 2011

I guess I've been so used to the presence of the 'public' schema that it seemed mandatory and, in a sense, much easier to design Pyrseas as if it was that way. I do recall reading that it can be dropped, but wondered "who would do such a thing?" In any case, you're correct. The docs even say 'public' is not even part of the SQL Standard. It may take a while for this to be fixed, but I'll look into it.

@jmafc
Copy link
Member

jmafc commented Aug 24, 2011

I have the folllowing change that is mostly a workaround. I've tested it on a database where I dropped schema 'public' and it seems to work.

diff --git a/pyrseas/dbconn.py b/pyrseas/dbconn.py
index d5de750..a74748d 100644
--- a/pyrseas/dbconn.py
+++ b/pyrseas/dbconn.py
@@ -48,7 +48,11 @@ class DbConnection(object):
                 self.host, self.port, self.dbname,
                 self.user or os.getenv("USER")),
                             connection_factory=DictConnection)
-        self._execute("set search_path to public, pg_catalog")
+        try:
+            self._execute("set search_path to public, pg_catalog")
+        except:
+            self.conn.rollback()
+            self._execute("set search_path to pg_catalog")
         self._version = int(self.fetchone("SHOW server_version_num")[0])

     def _execute(self, query):

If you could test from the above, I'd appreciate it.

@aquilax
Copy link
Author

aquilax commented Aug 25, 2011

Works like a charm. I tested it with and without public schema.

@aquilax aquilax closed this as completed Aug 25, 2011
jmafc added a commit that referenced this issue Aug 25, 2011
 * pyrseas/dbconn.py (DbConnection.connect): If set search_path fails
   with public schema, try again without it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants