On May 18, 2012, at 12:08 PM, Vinz wrote: > Hi all, > I'm writing some tests for my SqlAlchemy DB using the fixtures module, > and I'm currently trying to populate a one to many relationship. > http://farmdev.com/projects/fixture/using-dataset.html#referencing-foreign-dataset-classes > > File "/usr/local/lib/python2.6/dist-packages/fixture/base.py", line > 71, in setup > [ bla bla ... ] > File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/ > attributes.py", line 654, in get_all_pending > ret = [(instance_state(current), current)] > LoadError: AttributeError: 'list' object has no attribute > '_sa_instance_state' (with 'my_address' of
OK just for future reference, the "bla bla" part here is actually quite important in revealing what the issue is. In this case it is likely that you're appending a list somewhere, where a mapped object is expected, such as: myobject.some_attribute = [] or myobject.some_collection.append([]) but there might be configurational issues with the testing package you're using that's leading to this (so perhaps check with them). > > Where can I find some documentation about _sa_instance_state ? (didn't > find what that is) yeah unfortunate python issue here, this is SQLAlchemy attempting to procure an internal tracking object present on all mapped objects called "InstanceState". We use an "attribute getter" to get this, which is because it's very fast compared to a plain function, but the downside is in a lot of areas of the code we aren't transforming this attribute error into a nicely descriptive message (something which can be improved). The error means, "'list' instance is not a mapped object". > > Also, I don't quite understand the following warning from the fixture- > s doc : > " >>>> class Books(DataSet): > ... class two_worlds: > ... title = "Man of Two Worlds" > ... authors = [Authors.frank_herbert, Authors.brian_herbert] > > However, in some cases you may need to reference an attribute that > does not have a value until it is loaded, like a serial ID column. > (****Note that this is not supported by the SQLAlchemy data layer when > using sessions****.) To facilitate this, each inner class of a DataSet > gets decorated with a special method, ref(), that can be used to > reference a column value before it exists, i.e.: this isn't a SQLAlchemy question. Contact the author of that package for this. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.