Skip to content

Commit c91a446

Browse files
committed
#245 only bypass exception for get_model if in test / migration
1 parent 5c7131f commit c91a446

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

netbox_custom_objects/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ def ready(self):
9797
model = obj.get_model()
9898
get_serializer_class(model)
9999
except (DatabaseError, OperationalError, ProgrammingError) as e:
100-
# Only suppress exceptions during migrations/tests when schema may not match model
100+
# Only suppress exceptions during tests when schema may not match model
101+
# (is_running_migration is already handled by early return above)
101102
# During normal operation, re-raise to alert of actual problems
102-
if is_running_migration() or is_running_test():
103+
if is_running_test():
103104
# The transaction.atomic() block will automatically rollback
104105
pass
105106
else:
@@ -173,10 +174,11 @@ def get_models(self, include_auto_created=False, include_swapped=False):
173174
for through_model in model._through_models:
174175
yield through_model
175176
except (DatabaseError, OperationalError, ProgrammingError) as e:
176-
# Only suppress exceptions during migrations/tests when schema may not match model
177-
# (e.g., cache_timestamp column doesn't exist yet during migration/test setup)
177+
# Only suppress exceptions during tests when schema may not match model
178+
# (e.g., cache_timestamp column doesn't exist yet during test setup)
179+
# (is_running_migration is already handled by early return above)
178180
# During normal operation, re-raise to alert of actual problems
179-
if is_running_migration() or is_running_test():
181+
if is_running_test():
180182
# The transaction.atomic() block will automatically rollback
181183
pass
182184
else:

0 commit comments

Comments
 (0)