From 094dec72ac6e3f5d3f08c0e3536b16b7b086bfee Mon Sep 17 00:00:00 2001 From: asteroide Date: Fri, 27 Nov 2015 10:36:00 +0100 Subject: When deleting an intra-extension, deletion may be impossible due to foreign key constraints. Change-Id: I6a8421e80f68abdf80516f76b87f611249a1e80a --- keystone-moon/keystone/contrib/moon/backends/sql.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/keystone-moon/keystone/contrib/moon/backends/sql.py b/keystone-moon/keystone/contrib/moon/backends/sql.py index 06071507..a2c8f5bc 100644 --- a/keystone-moon/keystone/contrib/moon/backends/sql.py +++ b/keystone-moon/keystone/contrib/moon/backends/sql.py @@ -292,12 +292,6 @@ class Rule(sql.ModelBase, sql.DictBase): __all_objects__ = ( - Subject, - Object, - Action, - SubjectCategory, - ObjectCategory, - ActionCategory, SubjectScope, ObjectScope, ActionScope, @@ -305,6 +299,12 @@ __all_objects__ = ( ObjectAssignment, ActionAssignment, SubMetaRule, + SubjectCategory, + ObjectCategory, + ActionCategory, + Subject, + Object, + Action, Rule, ) @@ -375,8 +375,8 @@ class IntraExtensionConnector(IntraExtensionDriver): for _object in __all_objects__: query = session.query(_object) query = query.filter_by(intra_extension_id=intra_extension_id) - _ref = query.first() - if _ref: + _refs = query.all() + for _ref in _refs: session.delete(_ref) session.flush() session.delete(ref) @@ -948,6 +948,8 @@ class IntraExtensionConnector(IntraExtensionDriver): intra_extension_dict = dict(ref.intra_extension) intra_extension_dict["aggregation_algorithm"] = aggregation_algorithm_id setattr(ref, "intra_extension", intra_extension_dict) + session.flush() + LOG.debug("set_aggregation_algorithm_id {}-{} {}".format(intra_extension_id, aggregation_algorithm_id, self.get_aggregation_algorithm_id(intra_extension_id))) return self.get_aggregation_algorithm_id(intra_extension_id) def del_aggregation_algorithm(self, intra_extension_id): -- cgit 1.2.3-korg