On Jul 31, 4:50 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Jul 31, 2007, at 7:14 AM, Wojciech Smigaj wrote: > > > I get the following error: > > > Traceback (most recent call last): > > File "test_case.py", line 34, in ? > > session.merge(obj) > > File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.10-py2.4.egg/ > > sqlalchemy/orm/session.py", line 501, in merge > > raise exceptions.AssertionError("Instance %s has an instance key > > but is not persisted" % mapperutil.instance_str(object)) > > NameError: global name 'mapperutil' is not defined > > OK theres two errors there, one is our AssertionError is using an > unimported library, so thats a bug. but the error is that the object > youre giving it has an _instance_key but is not persisted in the > DB..thats because youve already deleted it. its actually looking in > the database for your item and not finding it. If you have flushed a > deleted object, its gone; you can either remove _instance_key from > your deleted object and save() it again, or make a totally new object > and save().
Thank you! Adding "obj.id = None; del obj._instance_key" after delete() made it work. > The usual pattern for "undoable operations" would proceed entirely > before any data is actually persisted to the database; i.e. the delete > () operation should be considered permanent, unless you are planning > on using a transaction ROLLBACK as your "undo". OK, thanks for the tip (and all your work on SQLAlchemy :-)). Best regards, Wojciech --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---