I think I've uncovered a bug in sqlalchemy's reflection feature. I've boiled down my existing postgres database to the following schema:

CREATE TABLE people
(
  person text PRIMARY KEY
) ;
CREATE TABLE prefs
(
  person text PRIMARY KEY REFERENCES people,
  name text
) ;
CREATE TABLE sites
(
  site text PRIMARY KEY
) ;
CREATE TABLE sites_config
(
  site text PRIMARY KEY REFERENCES sites
) ;


And the following python code:

from sqlalchemy import *
pg_engine = create_engine('postgres',
                        {'database':'alchemytest',
                        'host':'127.0.0.1',
                        'user':'dimator',
                        'password':'.....'}, )# echo=True)
tables = ['people','prefs','sites','sites_config']
for table in tables:
  print table
  t = Table(table, pg_engine, autoload = True)



Gives me the following traceback:
$ python test.py
people
prefs
Traceback (most recent call last):
  File "test.py", line 25, in ?
    t = Table(table, pg_engine, autoload = True)
File "/usr/lib/python2.3/site-packages/SQLAlchemy-0.1.0-py2.3.egg/ sqlalchemy/schema.py", line 90, in __call__
    engine.reflecttable(table)
File "/usr/lib/python2.3/site-packages/SQLAlchemy-0.1.0-py2.3.egg/ sqlalchemy/databases/postgres.py", line 253, in reflecttable
    ischema.reflecttable(self, table, ischema_names)
File "/usr/lib/python2.3/site-packages/SQLAlchemy-0.1.0-py2.3.egg/ sqlalchemy/databases/information_schema.py", line 172, in reflecttable table.c[constrained_column].append_item(schema.ForeignKey (remotetable.c[referred_column])) File "/usr/lib/python2.3/site-packages/SQLAlchemy-0.1.0-py2.3.egg/ sqlalchemy/util.py", line 60, in __getitem__
    raise KeyError(key)
KeyError: 'site'



The 'prefs' table does not reference the 'sites' table at all, so why is that KeyError occurring? I was going to open a ticket, but wasn't sure if I'm doing something obviously wrong.


--


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to