Created
December 13, 2016 00:29
-
-
Save hichihara/e8e50bb23a9d3e00afe5b18fa5eecbe2 to your computer and use it in GitHub Desktop.
tag revision number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/neutron/db/models/tag.py b/neutron/db/models/tag.py | |
index 6fb7a36..42ef18b 100644 | |
--- a/neutron/db/models/tag.py | |
+++ b/neutron/db/models/tag.py | |
@@ -28,3 +28,5 @@ class Tag(model_base.BASEV2): | |
standard_attr = orm.relationship( | |
'StandardAttribute', | |
backref=orm.backref('tags', lazy='joined', viewonly=True)) | |
+ revises_on_change = ('resource', ) | |
+ resource = None | |
diff --git a/neutron/services/tag/tag_plugin.py b/neutron/services/tag/tag_plugin.py | |
index 4164e82..18f38a0 100644 | |
--- a/neutron/services/tag/tag_plugin.py | |
+++ b/neutron/services/tag/tag_plugin.py | |
@@ -83,10 +83,12 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase): | |
with context.session.begin(subtransactions=True): | |
for tag_db in res.standard_attr.tags: | |
if tag_db.tag in tags_removed: | |
+ tag_db.resource = res | |
context.session.delete(tag_db) | |
for tag in tags_added: | |
tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id, | |
tag=tag) | |
+ tag_db.resource = res | |
context.session.add(tag_db) | |
return body | |
@@ -99,6 +101,7 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase): | |
with context.session.begin(subtransactions=True): | |
tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id, | |
tag=tag) | |
+ tag_db.resource = res | |
context.session.add(tag_db) | |
except db_exc.DBDuplicateEntry: | |
pass | |
@@ -109,7 +112,9 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase): | |
with context.session.begin(subtransactions=True): | |
query = context.session.query(tag_model.Tag) | |
query = query.filter_by(standard_attr_id=res.standard_attr_id) | |
- query.delete() | |
+ for tag_db in query.all(): | |
+ tag_db.resource = res | |
+ context.session.delete(tag_db) | |
@log_helpers.log_method_call | |
def delete_tag(self, context, resource, resource_id, tag): | |
@@ -118,8 +123,11 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase): | |
query = context.session.query(tag_model.Tag) | |
query = query.filter_by(tag=tag, | |
standard_attr_id=res.standard_attr_id) | |
- if not query.delete(): | |
+ tag_db = query.first() | |
+ if not tag_db: | |
raise tag_ext.TagNotFound(tag=tag) | |
+ tag_db.resource = res | |
+ context.session.delete(tag_db) | |
# support only _apply_dict_extend_functions supported resources | |
# at the moment. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment