Skip to content

Commit 08b244a

Browse files
committed
mitigates issue of pruning newly used tags #401
1 parent 29b0296 commit 08b244a

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

module/netbox/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def delete_unused_tags(self):
928928
if tag_description is None or not tag_description.startswith(self.primary_tag):
929929
continue
930930

931-
if tag_tagged_items is None or tag_tagged_items != 0:
931+
if tag_tagged_items is None or tag_tagged_items != 0 or this_tag.used is True:
932932
continue
933933

934934
log.info(f"Deleting unused tag '{this_tag.get_display_name()}'")

module/netbox/object_classes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,10 @@ def compile_tags(self, tags, remove=False):
909909

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

912+
# mark tag as used in order to not delete newly used tags
913+
if isinstance(tag, NBTag):
914+
tag.used = True
915+
912916
new_tags.append(tag)
913917

914918
if tag_name in current_tag_strings and remove is True:
@@ -940,7 +944,7 @@ def update_tags(self, tags, remove=False):
940944
941945
Parameters
942946
----------
943-
tags: (str, list, dict, NBTag)
947+
tags: str, list, dict, NBTag
944948
tags to parse and add/remove to/from current list of object tags
945949
remove: bool
946950
True if tags shall be removed, otherwise they will be added
@@ -1269,6 +1273,7 @@ def __init__(self, *args, **kwargs):
12691273
"description": 200,
12701274
"tagged_items": int
12711275
}
1276+
self.used = False
12721277
super().__init__(*args, **kwargs)
12731278

12741279

0 commit comments

Comments
 (0)