SQLAlchemy: Modification of detached object
this case is available using the make_transient() helper function:
inst = session.query(Model).first()session.expunge(inst)make_transient(inst)inst.id = Nonesession.add(inst)session.flush()print inst.id #New ID
def duplicate(self): arguments = dict() for name, column in self.__mapper__.columns.items(): if not (column.primary_key or column.unique): arguments[name] = getattr(self, name) return self.__class__(**arguments)