Skip to content

Commit

Permalink
mitigates issue of pruning newly used tags #401
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Nov 20, 2024
1 parent 29b0296 commit 08b244a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion module/netbox/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def delete_unused_tags(self):
if tag_description is None or not tag_description.startswith(self.primary_tag):
continue

if tag_tagged_items is None or tag_tagged_items != 0:
if tag_tagged_items is None or tag_tagged_items != 0 or this_tag.used is True:
continue

log.info(f"Deleting unused tag '{this_tag.get_display_name()}'")
Expand Down
7 changes: 6 additions & 1 deletion module/netbox/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ def compile_tags(self, tags, remove=False):

tag = self.inventory.add_update_object(NBTag, data={"name": tag_name})

# mark tag as used in order to not delete newly used tags
if isinstance(tag, NBTag):
tag.used = True

new_tags.append(tag)

if tag_name in current_tag_strings and remove is True:
Expand Down Expand Up @@ -940,7 +944,7 @@ def update_tags(self, tags, remove=False):
Parameters
----------
tags: (str, list, dict, NBTag)
tags: str, list, dict, NBTag
tags to parse and add/remove to/from current list of object tags
remove: bool
True if tags shall be removed, otherwise they will be added
Expand Down Expand Up @@ -1269,6 +1273,7 @@ def __init__(self, *args, **kwargs):
"description": 200,
"tagged_items": int
}
self.used = False
super().__init__(*args, **kwargs)


Expand Down

0 comments on commit 08b244a

Please sign in to comment.