Thanks Michael, that did the trick. Using the mutable thing is only a small comfort in my case compared to the extra design it takes.
for the sake of completeness here is what works: newuser = User(email,name,password) newuser.notebooks.append(Notebook("My Notes")) newuser.views = {} session.add(newuser) session.commit() user = session.query(User).filter_by(email=email).one() views = {} views['lastview'] = user.notebooks[0].id user.views = views session.commit() session.close() Zoltan. On Tuesday, March 12, 2013 4:33:32 PM UTC+1, Michael Bayer wrote: > > if you want to do this "manually", just reassign to the attribute which > will trigger it: > > myobject.mypickle = {<dictionary>} > > > the "mutation" thing is only if you want in-place tracking, that is: > > myobject.mypickle['newvalue'] = 'something' > > > > On Mar 12, 2013, at 11:15 AM, Zoltan Giber <zgi...@gmail.com <javascript:>> > wrote: > > Thanks Matthew, > > I see that this would be a way, but I'm not very experienced, and > introducing a new custom type feels like an overkill. I only have three > pickletype in my whole app, and i don't mind to set "dirty" manually when I > update them. I don't want to query against their values either. > > I was hoping that the mutable=True flag which is True by default according > the documentation is exactly what i need, but no luck so far.. > > On Tuesday, March 12, 2013 3:39:10 PM UTC+1, Matthew Desmarais wrote: >> >> Hi Zoltan, >> >> On Tue, Mar 12, 2013 at 9:56 AM, Zoltan Giber <zgi...@gmail.com> wrote: >> > I'm new to sqlalchemy, writing my first app using it. I stumbled upon a >> weird thing; my user object has a pyckletype >> > representing a python dict, which i can't find a way to update. I >> assumed, that a change in the pickled object will >> > somehow trigger "dirty" and my new data should be there, but it is not. >> My goal would be to create an user, and a >> > notebook for the user, then add the notebook's ID to the >> user.views['lastopened'] >> > >> > Looking at the code it will be clear i hope (i'm adding some comments >> here): >> > >> > newuser = User(email,name,password) >> # creating the new user >> > newuser.notebooks.append(Notebook("My Notes")) >> # the child notebook >> > newuser.views = {} >> > session.add(newuser) >> > session.commit() # couldn't find other way to get the >> notebook id, but to make a commit. is there a >> > better way? >> > >> > user = session.query(User).filter_by(email=email).one() >> # I'm not sure if a new query is needed here, >> > this is eliminating uncertainty >> > defaultnb = user.notebooks[0] >> > user.views['lastview'] = defaultnb.id >> > session.commit() >> > session.close() >> > >> > the problem is, that the user.view['lastview'] stays an empty {} ... if >> i update it upon creation, it works, but then the >> > notebook.id is not known to me. >> >> I've not done this myself, but I was curious so I looked in the >> sqlalchemy docs for PickleType [0]. I found a note that sounds >> applicable: "To allow ORM change events to propagate for elements >> associated with PickleType, see Mutation Tracking [1]". I hope this is >> helpful. >> >> Thanks, >> Matthew >> >> [0] >> http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#sqlalchemy.types.PickleType >> >> [1] http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/mutable.html >> > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+...@googlegroups.com <javascript:>. > To post to this group, send email to sqlal...@googlegroups.com<javascript:> > . > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.