本文整理汇总了Python中database.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_smu_info_from_cco
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import flush [as 别名]
def get_smu_info_from_cco(self, platform, release):
same_as_db = False
db_session = DBSession()
platform_release = platform + '_' + release
try:
self.smu_meta = SMUMeta(platform_release=platform_release)
# Load data from the SMU XML file
self.load()
# This can happen if the given platform and release is not valid.
# The load method calls get_smu_info_from_db and failed.
if self.smu_meta is None:
return
db_smu_meta = db_session.query(SMUMeta).filter(SMUMeta.platform_release == platform + '_' + release).first()
if db_smu_meta is not None:
if db_smu_meta.created_time == self.smu_meta.created_time:
same_as_db = True
else:
# Delete the existing smu_meta and smu_info for this platform and release
db_session.delete(db_smu_meta)
if not same_as_db:
db_session.add(self.smu_meta)
else:
db_smu_meta.retrieval_time = datetime.datetime.utcnow()
# Use Flush to detect concurrent saving condition. It is
# possible that another process may perform the same save.
# If this happens, Duplicate Key may result.
db_session.flush()
db_session.commit()
except IntegrityError:
db_session.rollback()
except Exception:
db_session.rollback()
logger.exception('get_smu_info_from_cco() hit exception')