Re: couple bugs with schema

Jacob Smullyan <[email protected]> Thu, 12 Jan 2006 23:34:34 -0500
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Thu, Jan 12, 2006 at 05:47:35PM -0700, Jonathan Ellis wrote:
> autoschema(schema='pg_catalog') throws an exception (PG 8.1):
> 
> >>> pydo.autoschema('cf', schema='pg_catalog')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "pydo\base.py", line 844, in autoschema
>     obj=type(Table, (PyDO,), d)
>   File "pydo\base.py", line 84, in __init__
>     gfields, gunique=cls._getTableDescription()
>   File "pydo\base.py", line 200, in _getTableDescription
>     data=cls.getDBI().describeTable(cls.getTable(False), cls.schema)
>   File "pydo\drivers\psycopgconn.py", line 288, in describeTable
>     fields[L[0]].unique = True
> KeyError: -2

The same exception is thrown with PG 8.0.1, and probably with earlier
versions.  According to the postgresql documentation,
pg_attribute.attnum for system columns like oid have arbitrary
negative values.  See:

  http://www.postgresql.org/docs/8.1/interactive/catalog-pg-attribute.html

I have to point out that you contributed this code:).  

Now, we could decide not to support those values and simply skip them;
I attach the obvious patch against svn HEAD that does that.  It passes
the regression tests and works at generating classes against
pg_catalog.  But whether the indices it is skipping are appropriate
ones to skip I haven't taken the time to find out; since you are
apparently doing some black magic with pg_catalog anyway, maybe you're
in a better position to do so.  Let me know what you think.

> autoschema(schema='xxy') returns classes found in schema xxy, but if
> there is a table with the same name defined in the public schema for
> any of those classes, name, it will return the definition from the
> table in public.

Interesting; I don't see the problem in the SQL, but it must be there.
I'll look into it and report back later.

Cheers,

js


-- 
Jacob Smullyan
psycopg_describeTable.patch (text/plain, 640 B)
Index: src/pydo/drivers/psycopgconn.py
===================================================================
--- src/pydo/drivers/psycopgconn.py	(revision 1700)
+++ src/pydo/drivers/psycopgconn.py	(working copy)
@@ -281,7 +281,9 @@
             debug("SQL: %s", (sql,))
         cur.execute(sql, (qtable,schema))
         for row in cur.fetchall():
-            L = [int(i) for i in row[0].split(' ')]
+            L = filter(lambda x: x>=0, [int(i) for i in row[0].split(' ')])
+            if not L:
+                continue
             if self.verbose:
                 debug("Found unique index on %s" % L)
             if len(L) == 1:
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDxy3auqamFyFXXLIRAouPAJ9YMxx99n7V5wqCJCL01IefzlpPSwCgmHOF
pSa6zc7AV1FRi1JAg3bywUA=
=72+m
-----END PGP SIGNATURE-----