HI I have following code,
@db_error_handler def execute_query(self, query_str, data=None): '''Execute DB query and retry for common DB interaction errors''' errors_concerned = [1213, 1205, 2013, 2006] attempts = 1 while(True): try: result = self.session.execute(query_str, data) #result.close() : Trying to commonize insert/select self.session.commit() return result except OperationalError as oe: self.session.rollback() if oe.orig[0] in errors_concerned: if attempts <= 3: logger.error("Error occured in attempts %s: %s" % (attempts, oe.orig)) time.sleep(2 * attempts) attempts += 1 continue else: logger.error("Error occured, attempts exhausted %s: %s" % (attempts, oe.orig)) break else: raise I am constructing the queries outside and passing to this function. I want to return result in case of select queries. But I can not do that if I call result.close() before returning. Without closing the result, insert queries have a problem. ERROR: DB operation failure: (ProgrammingError) (2014, "Commands out of sync; you can't run this command now") None None So I was thinking of using is_insert¶ <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy.is_insert> True if this ResultProxy <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy> is the result of a executing an expression language compiled expression.insert() <http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html#sqlalchemy.sql.expression.insert> construct. When True, this implies that the inserted_primary_key <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy.inserted_primary_key> attribute is accessible, assuming the statement did not include a user defined “returning” construct. to check if the query resulted in insert and then call close skip otherwise ? Is it ok from semantic point of view ? Also will it result it inconsistent connection state or connections ? -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.