Hi, instead of db.session.add, what you want is:
import = db.session.merge(import) See http://www.sqlalchemy.org/docs/orm/session.html#merging : "It examines the primary key of the instance. If it’s present, it attempts to load an instance with that primary key (or pulls from the local identity map" Maybe you were confused by the heading "Adding New *or Existing* Items" in http://www.sqlalchemy.org/docs/orm/session.html#adding-new-or-existing-items ... here the "existing" part only applies to *detached* instances (ones that were previously associated with a session but have been removed), not to *transient* ones (new instances that SQLAlchemy hasn't already seen). Transient instances are assumed new by session.add, it doesn't query the database to check if the primary key exists. See "Quickie Intro to Object States" http://www.sqlalchemy.org/docs/orm/session.html#quickie-intro-to-object-states and then the rest of the Session tutorial; that should get you going. Regards, - Gulli -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/6lI0LZnLNpYJ. 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.
