- attached comparetest.py
error comparing assocation proxy of attribute mapped collection
Issue #2176
resolved
I discovered this while writing tests for a model which implements a dictionary-style access to a column of a related class. I can reproduce this on SQLAlchemy 0.6.6 and 0.6.7 (have not tried 0.7 yet) using the attached script. The resulting traceback is:
Traceback (most recent call last):
File "bin/py", line 98, in <module>
execfile(__file__)
File "/tmp/x.py", line 54, in <module>
assert art.attributes=={'foo': 'bar'}
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/ext/associationproxy.py", line 179, in __get__
proxy = self._new(_lazy_collection(obj, self.target_collection))
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/ext/associationproxy.py", line 227, in _new
self.collection_class = util.duck_type_collection(lazy_collection())
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/ext/associationproxy.py", line 307, in __call__
return getattr(obj, self.target)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/orm/attributes.py", line 168, in __get__
instance_dict(instance))
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/orm/attributes.py", line 392, in get
return self.set_committed_value(state, dict_, value)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/orm/attributes.py", line 810, in set_committed_value
collection.append_without_event(item)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/orm/collections.py", line 560, in append_without_event
getattr(self._data(), '_sa_appender')(item, _sa_initiator=False)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.6.7-py2.7.egg/sqlalchemy/orm/collections.py", line 1418, in set
key = self.keyfunc(value)
TypeError: attribute name must be a string
Comments (4)
-
Account Deleted -
Account Deleted SQLAlchemy 0.7 has the same behaviour with identical traceback.
-
repo owner - changed component to documentation
- changed milestone to 0.7.1
- changed status to wontfix
attr_name is a string, passed to Python operator.attrgetter. Added a clarification for this in a3a547324eff14c0247c903cb2aa415123661c29.
i.e.
collection_class=attribute_mapped_collection("field"))
-
repo owner - removed milestone
Removing milestone: 0.7.1 (automated comment)
- Log in to comment
Script to reproduce the error