I've written code similar to this with no problems.

Are you using assign_mapper? If so, the save() call is unnecessary.

Do you get this error on the first object or on some subsequent object?

Barry

----- Original Message ----
From: Lukasz Szybalski <[EMAIL PROTECTED]>
To: [email protected]
Sent: Monday, October 22, 2007 3:54:03 PM
Subject: [sqlalchemy] multiple inserts of sqlalchemy instances?



Hello,
I need to save data multiple times in a for loop.

I was trying to do something like this:

You are able to select which group you want to be in: A,B,C,D....

for record in userchoice:
    new=model.User()
    #set some variables
   if record.group=='A':
      #set some more fields
      new.save()
      new.flush()
   elif record.group=='B':
      #set some more fields
      new.save()
      new.flush()

If I do that I get:

File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py", line
838, in save_obj
    raise exceptions.FlushError("New instance %s with identity key %s
conflicts with persistent instance %s" %
(mapperutil.instance_str(obj), str(instance_key),
mapperutil.instance_str(existing)))
FlushError: New instance [EMAIL PROTECTED] with identity key (<class
'XXX.model.User'>, (19527, None), None) conflicts with persistent
instance [EMAIL PROTECTED]

Is there a way to do multiple inserts with sqlalchemy?

Lucas


-- 
-- 
Vim auto completion for python
http://lucasmanual.com/mywiki/FrontPage#head-8ce19b13e89893059e126b719bebe4ee32fe103c
TurboGears from start to finish:
http://www.lucasmanual.com/mywiki/TurboGears







__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to