Are There Any Side Effects From Calling Sqlalchemy Flush() Within Code?
A bit of background: I am using pyramid framework with SQLAlchemy. My db session is handled by pyramid_tm and ZTE DBSession = scoped_session(sessionmaker(extension=ZopeTransactionE
Solution 1:
It is very hard to say why you used to get IntegrityError
's without seeing any code, but in theory there are a few scenarios where autocommit
may actually cause it by flushing the session prematurely. For example:
COURSE_ID = 10student = Student(name="Bob")
student.course_id = COURSE_ID
course = Course(id=COURSE_ID, name="SQLAlchemy")
The above code will probably (haven't tested) fail with autocommit
turned on and should succeed if you let SQLAlchemy to flush the changes.
I don't think there's any harm in flushing the session periodically if it helps, but again, it's hard to tell whether something can be done to avoid the manual flush without any code samples.
Post a Comment for "Are There Any Side Effects From Calling Sqlalchemy Flush() Within Code?"