I thought I understood the behaviour of session.merge() from reading the
documentation, but I'm wrong. Here is an example. I have codes below,
class User(Base):
> __tablename__ = 'user'
> id = Column(Integer, primary_key=True)
> name = Column(String(50), nullable=False)
> addresses = relationship("Address", backref="user")
This class has a corresponding table 'user' which has already been
populated with one row, with its primary key equal to 1.
Now I run the following instructions from python -i:
> >>> u = User(id=1)
> >>> session.merge(u)
> >>> session.commit()
I expected that there should be a sqlalchemy.orm.exc.FlushError, because
both object u (which has been merged) and the row which has been already in
the table have their primary key equal to 1. However, nothing happened.
Sqlalchemy just ignored that merged u!
If I do these instructions:
> >>> session.add(u)
> >>> session.commit()
Then I got a sqlalchemy.orm.exc.FlushError, which was expected.
So, session.merge() does not include .add()? From the documentation it
seems that it does.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.