Skip to content

Commit 8d14619

Browse files
committed
#338 rework startup logic
1 parent 5e388f2 commit 8d14619

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

netbox_custom_objects/__init__.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,11 @@ def ready(self):
100100
super().ready()
101101
return
102102

103-
try:
104-
with transaction.atomic():
105-
qs = CustomObjectType.objects.all()
106-
for obj in qs:
107-
model = obj.get_model()
108-
get_serializer_class(model)
109-
except (DatabaseError, OperationalError, ProgrammingError):
110-
# Only suppress exceptions during tests when schema may not match model
111-
# During normal operation, re-raise to alert of actual problems
112-
if "test" in sys.argv:
113-
# The transaction.atomic() block will automatically rollback
114-
pass
115-
else:
116-
raise
103+
with transaction.atomic():
104+
qs = CustomObjectType.objects.all()
105+
for obj in qs:
106+
model = obj.get_model()
107+
get_serializer_class(model)
117108

118109
super().ready()
119110

@@ -170,27 +161,17 @@ def get_models(self, include_auto_created=False, include_swapped=False):
170161
# Add custom object type models
171162
from .models import CustomObjectType
172163

173-
try:
174-
with transaction.atomic():
175-
custom_object_types = CustomObjectType.objects.all()
176-
for custom_type in custom_object_types:
177-
model = custom_type.get_model()
178-
if model:
179-
yield model
180-
181-
# If include_auto_created is True, also yield through models
182-
if include_auto_created and hasattr(model, '_through_models'):
183-
for through_model in model._through_models:
184-
yield through_model
185-
except (DatabaseError, OperationalError, ProgrammingError):
186-
# Only suppress exceptions during tests when schema may not match model
187-
# (e.g., cache_timestamp column doesn't exist yet during test setup)
188-
# During normal operation, re-raise to alert of actual problems
189-
if "test" in sys.argv:
190-
# The transaction.atomic() block will automatically rollback
191-
pass
192-
else:
193-
raise
164+
with transaction.atomic():
165+
custom_object_types = CustomObjectType.objects.all()
166+
for custom_type in custom_object_types:
167+
model = custom_type.get_model()
168+
if model:
169+
yield model
170+
171+
# If include_auto_created is True, also yield through models
172+
if include_auto_created and hasattr(model, '_through_models'):
173+
for through_model in model._through_models:
174+
yield through_model
194175

195176

196177
config = CustomObjectsPluginConfig

0 commit comments

Comments
 (0)