Postgis+sqlalchemy - KeyError: geometry

697 views
Skip to first unread message

Mando

unread,
Jan 20, 2008, 11:57:31 AM1/20/08
to sqlalchemy
Hi,
I'm trying to update somes values into a postgis layer through
sqlalchemy, but, when I connect with the table I receive this message:

Traceback (most recent call last):
File "/Applications/qgis0.9.0.app/Contents/MacOS/share/qgis/python/
plugins/sortpglayer_plugin/pyarchinit_dbconn.py", line 354, in
<module>
query.fields_list('poligono')
File "/Applications/qgis0.9.0.app/Contents/MacOS/share/qgis/python/
plugins/sortpglayer_plugin/pyarchinit_dbconn.py", line 343, in
fields_list
table = Table(self.table_name, self.metadata, autoload=True)
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/schema.py", line
143, in __call__
metadata.get_engine().reflecttable(table)
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/engine/base.py",
line 505, in reflecttable
self.dialect.reflecttable(conn, table)
File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/databases/
postgres.py", line 385, in reflecttable
coltype = ischema_names[attype]
KeyError: 'geometry'

I'm working on mac os x 10.4, python 2.5, SQLAlchemy-0.3.3,
psycopg2-2.0.6, pgsql821+postgis121-1

Somes suggestions???

Thanks a lot!

Michael Bayer

unread,
Jan 20, 2008, 12:01:41 PM1/20/08
to sqlal...@googlegroups.com

On Jan 20, 2008, at 11:57 AM, Mando wrote:

>
>
> I'm working on mac os x 10.4, python 2.5, SQLAlchemy-0.3.3,
> psycopg2-2.0.6, pgsql821+postgis121-1
>

upgrade to at least 0.3.11, the unknown column type of "geometry" will
produce a generically-typed column and a warning message.

Mando

unread,
Jan 20, 2008, 12:17:51 PM1/20/08
to sqlalchemy
Ok, and thanks a lot!!!!

Mando

unread,
Jan 20, 2008, 12:42:44 PM1/20/08
to sqlalchemy
No, the problem appears also with SQLAlchemy-0.3.11 and
SQLAlchemy-0.4.2p3.

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/databases/postgres.py:
509: RuntimeWarning: Did not recognize type 'geometry' of column
'the_geom'
warnings.warn(RuntimeWarning("Did not recognize type '%s' of column
'%s'" % (attype, name)))


/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/SQLAlchemy-0.3.11-py2.5.egg/sqlalchemy/databases/postgres.py:
457: RuntimeWarning: Did not recognize type 'geometry' of column
'the_geom'
warnings.warn(RuntimeWarning("Did not recognize type '%s' of column
'%s'" % (attype, name)))

Mando

unread,
Jan 20, 2008, 1:09:34 PM1/20/08
to sqlalchemy
With SQLAlchemy-0.4.2p3 I've solved the problem in this (terrible!!!)
way:
I've added an 'if' into postgres.py file at line 514 and now work
correctly. I maje this beacause I don't know how add a column type
into sqlalchemy code:

else:
if attype != 'geometry':
warnings.warn(RuntimeWarning("Did not recognize
type '%s' of column '%s'" % (attype, name)))
coltype = sqltypes.NULLTYPE

: ) : )

Bye bye

mando

Michael Bayer

unread,
Jan 20, 2008, 1:14:55 PM1/20/08
to sqlal...@googlegroups.com

its only a warning, that theres no "Geometry" type available in SA.
but your program is safe to continue, assuming you havent changed the
warnings filter to raise exceptions.

info on the warnings filter:

http://www.python.org/doc/2.4.2/lib/warning-filter.html

Reply all
Reply to author
Forward
0 new messages