Skip to content

Commit 3391f6d

Browse files
authored
Merge pull request #155 from netboxlabs/107-remove-warnings
Cleanup warning messages
2 parents 04988ae + 29f8b10 commit 3391f6d

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

netbox_custom_objects/models.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import decimal
22
import re
3+
import warnings
34
from datetime import date, datetime
45

56
import django_filters
@@ -36,8 +37,8 @@
3637
ExportTemplatesMixin,
3738
JournalingMixin,
3839
NotificationsMixin,
39-
get_model_features,
4040
TagsMixin,
41+
get_model_features,
4142
)
4243
from netbox.registry import registry
4344
from utilities import filters
@@ -439,15 +440,22 @@ def wrapped_post_through_setup(self, cls):
439440

440441
TM.post_through_setup = wrapped_post_through_setup
441442

442-
try:
443-
model = type(
444-
str(model_name),
445-
(CustomObject, models.Model),
446-
attrs,
443+
# Suppress RuntimeWarning about model already being registered
444+
# TODO: Remove this once we have a better way to handle model registration
445+
with warnings.catch_warnings():
446+
warnings.filterwarnings(
447+
"ignore", category=RuntimeWarning, message=".*was already registered.*"
447448
)
448-
finally:
449-
# Restore the original method
450-
TM.post_through_setup = original_post_through_setup
449+
450+
try:
451+
model = type(
452+
str(model_name),
453+
(CustomObject, models.Model),
454+
attrs,
455+
)
456+
finally:
457+
# Restore the original method
458+
TM.post_through_setup = original_post_through_setup
451459

452460
# Register the main model with Django's app registry
453461
try:

0 commit comments

Comments
 (0)