OpenStack每日Merge关注20140928
2014-09-28 14:45
176 查看
【review地址】
To view, visit https://review.openstack.org/#/c/124112/
【merge目标】
给Session.commit()方法添加_wrap_db_error装饰器
【评价】
装饰器的一个鲜活的例子:
使用装饰器装饰方法
To view, visit https://review.openstack.org/#/c/124112/
【merge目标】
给Session.commit()方法添加_wrap_db_error装饰器
【评价】
装饰器的一个鲜活的例子:
def _wrap_db_error(f): #TODO(rpodolyaka): in a subsequent commit make this a class decorator to # ensure it can only applied to Session subclasses instances (as we use # Session instance bind attribute below) @functools.wraps(f) def _wrap(self, *args, **kwargs): try: return f(self, *args, **kwargs) except UnicodeEncodeError: raise exception.DBInvalidUnicodeParameter() except sqla_exc.OperationalError as e: _raise_if_db_connection_lost(e, self.bind) _raise_if_deadlock_error(e, self.bind.dialect.name) # NOTE(comstud): A lot of code is checking for OperationalError # so let's not wrap it for now. raise # note(boris-42): We should catch unique constraint violation and # wrap it by our own DBDuplicateEntry exception. Unique constraint # violation is wrapped by IntegrityError. except sqla_exc.IntegrityError as e: # note(boris-42): SqlAlchemy doesn't unify errors from different # DBs so we must do this. Also in some tables (for example # instance_types) there are more than one unique constraint. This # means we should get names of columns, which values violate # unique constraint, from error message. _raise_if_duplicate_entry_error(e, self.bind.dialect.name) raise exception.DBError(e) except Exception as e: LOG.exception(_LE('DB exception wrapped.')) raise exception.DBError(e) return _wrap
使用装饰器装饰方法
@_wrap_db_error def commit(self, *args, **kwargs): return super(Session, self).commit(*args, **kwargs)
相关文章推荐
- openstack 每日Merge关注20140919
- OpenStack每日Merge关注20140930
- OpenStack每日Merge关注20140923
- 每日区块链:以太坊“拜占庭”硬分叉即将出现,人们该如何关注?
- (每日更新)里里,阿里里,阿里阿里里:【第一期】喜欢的记得关注哈
- 【每日安全资讯】谷歌站上被告席:个人隐私“被遗忘权”受关注
- 每日区块链:日立与瑞穗达成合作开发区块链供应链;区块链技术将在医疗行业面临不小挑战 患者信息安全成关注点
- 每日必读DZone News—对DevOps的关注
- [原]每日头条(200709)——自有新视角:一条热点新闻、一项业界动态、一个另类点子……,关注我们的社会、关注我们的行业、关注我们的思想
- 每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询
- 每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询
- leetcode:88 Merge Sorted Array-每日编程第三十一题
- 昨日关注-每日编译(DailyBuild) 参考
- 关注 OpenStack 的筒子们,福利来啦!
- 【每日好文分享】—— 共1000篇,春节除外天天坚持更新,敬请博友们天天关注~
- 【leetcode每日一题】23.Merge k Sorted Lists
- 【leetcode每日一题】NO21.Merge Two Sorted Lists
- OpenStack发布第16个版本Pike,关注基础设施可组合性
- [每日一题] OCP1z0-047 :2013-08-16 merge的用法............................................
- [每日一题] OCP1z0-047 :2013-08-16 merge的用法....................................................45