[sqlalchemy] Re: dictionaries collection_class

2007-06-18 Thread Ron
Ok, I applied that change to the version I'm using (0.3.8). That fixed it. But I think I stumbled on another bug/inconcistancy. If I tried to str/repr obj.attr it failed. I looked around the code and this fix seemed to work, but I'm not sure if it fits in with how the class is intended to

[sqlalchemy] Re: dictionaries collection_class

2007-06-18 Thread jason kirtland
Ron wrote: Ok, I applied that change to the version I'm using (0.3.8). That fixed it. But I think I stumbled on another bug/inconcistancy. If I tried to str/repr obj.attr it failed. [...] Does that make sense? Or is the problem deeper in the code? It seems to go along with what you

[sqlalchemy] Re: dictionaries collection_class

2007-06-16 Thread Ron
Now I'm having trouble with updating values in AttributeDict: so obj.attrs['key'] = 'somevalue' (works) obj.attrs['key'] = 'newvalue'(second one doesn't work) I get this error: File /usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.8- py2.4.egg/sqlalchemy/orm/mapper.py, line 679,

[sqlalchemy] Re: dictionaries collection_class

2007-06-16 Thread Ron
Now I'm having trouble with updating values in AttributeDict: so obj.attrs['key'] = 'somevalue' (works) obj.attrs['key'] = 'newvalue'(second one doesn't work) I get this error: File /usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.8- py2.4.egg/sqlalchemy/orm/mapper.py, line 679,

[sqlalchemy] Re: dictionaries collection_class

2007-06-16 Thread jason kirtland
Ron wrote: Now I'm having trouble with updating values in AttributeDict: so obj.attrs['key'] = 'somevalue' (works) obj.attrs['key'] = 'newvalue'(second one doesn't work) I get this error: File /usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.8-

[sqlalchemy] Re: dictionaries collection_class

2007-06-12 Thread sdobrev
the legal way is the association_proxy and family. here another shorter ... a hack: i did have similar need - obj.somerelation.append( left=.., right=..), so i did monkeypatch the InstrumentedList's append to use the item returned from collection's append - def append( self, *args,

[sqlalchemy] Re: dictionaries collection_class

2007-06-12 Thread Ron
Using the association_proxy extension in combination with your dictionary collection class is an easy way to get this kind of simplified access. Assuming your Attribute's value is in a property called 'value', you can set up simple dict access like so: class Obj(object): attrs =

[sqlalchemy] Re: dictionaries collection_class

2007-06-12 Thread jason kirtland
Ron wrote: When I try the above I get this error at flush time: InvalidRequestError: Class 'str' entity name 'None' has no mapper associated with it Here is my dictionary collection_class: class AttributeDictNEW(dict): My Attribute Dict def append(self, item):

[sqlalchemy] Re: dictionaries collection_class

2007-06-12 Thread Ron
The association proxy will take care of Attribute construction for you, so you can get away with just: class AttributeDictNEW(dict): def append(self, item): self[item.key] = item def __iter__(self): return self.itervalues() So now I if I try to get something