TypeError: 'instancemethod' object does not support item assignment

900 views
Skip to first unread message

SeanInSeattle

unread,
Sep 6, 2010, 2:54:37 PM9/6/10
to sqlalchemy
Here's what I've got:

from sqlalchemy import *
from sqlalchemy.orm import *
from web.models.card import *
connectionString = "postgresql://www:www@localhost/prod"
databaseEngine = create_engine(connectionString)
sessionFactory = sessionmaker(autoflush = True, autocommit = False,
bind = databaseEngine)
session = sessionFactory()
CardsCollection = session.query(card).all()
_content = {}
for index in range(0, len(CardsCollection)):
c = CardsCollection[index]
_content[index] = c
print json.dumps(_content)

And here's the error:

Traceback (most recent call last):
File "/home/src/py/raspberry/src/dictionaryTest.py", line 15, in
CardsCollection = session.query(card).all()
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/
query.py", line 1453, in all
return list(self)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/
query.py", line 1676, in instances
rows = [process[0](row, None) for row in fetch]
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/
mapper.py", line 2234, in _instance
populate_state(state, dict_, row, isnew, only_load_props)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/
mapper.py", line 2113, in populate_state
populator(state, dict_, row)
File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/
strategies.py", line 127, in new_execute
dict_[key] = row[col]
TypeError: 'instancemethod' object does not support item assignment

Can someone help me out with this? I've tried a few things, and
researched into how dictionaries work... but its just not jumping out
at me.

Michael Bayer

unread,
Sep 6, 2010, 4:53:46 PM9/6/10
to sqlal...@googlegroups.com

On Sep 6, 2010, at 2:54 PM, SeanInSeattle wrote:

> Here's what I've got:

That's not all you've got, the way your "card" class is defined and mapped is pretty important here. The error you have is likely because you've mapped a column the same name as a method on your "card" class.

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

Reply all
Reply to author
Forward
0 new messages