Hi, folks,
I observed that it seems all ORM objects in a session will expire
immediately if there is a failure in session.flush(). I was wondering
what's the rationale behind this behavior.
Following is an artificial web application code to illustrate the idea:
def PUT():
....
# session and engine are all created with default parameter
user = session.query(UserProfile).first()
# deliberately tries to insert a Login record which has the same
primary key as an existing one such that the later session.flush() will fail
try:
duplicated_login_record = Login(id=0, username="username:weikai")
session.add(duplicated_login_record)
session.flush()
except IntegrityError:
session.rollback()
print user.id
...
By turning on logging, I noticed the "print user.id" line always result in
a new SELECT being issued to database, which is an indicator that somehow
user object got expired after the failure in session.flush().
For some other good reason which I don't want to elaborate here, we really
don't want to have an extra SELECT going to DB in the processing of one
HTTP request. Therefore, I was just wondering why is this behavior and
whether it can be turned off.
--
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.