RFC: Fixes #20290: Prevent ObjectType queries when table doesn't exist #1155

Closed
opened 2026-04-05 21:14:19 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jnovinger on 10/2/2025

Fixes: #20290

In v4.4.0, ObjectType became a concrete model with a database table. Signal handlers query this table during migrations, but the table doesn't exist yet during 3.7.x→4.4.0 upgrades. The query failures poison the transaction and abort migrations.

This commits adds a objecttype_table_exists() helper and and uses it in three places:

  • has_feature() in netbox/models/features.py
  • update_object_types() in core/signals.py
  • Search backend cache() in search/backends.py

If core_objecttype table doesn't exist, operations return early instead of querying. Once table exists, normal operation resumes.

Pros

  • no migration changes
  • one helper function, three identical checks
  • easy to test, verify, and remove later if needed
  • queries PostgreSQL system catalogs for table existence - won't poison transactions

Cons

  • fixes symptoms, not root cause
  • touches 3 different files instead of one surgical fix
  • future code querying ObjectType during migrations could still fail/future developers might not know to add this check in new code
  • adds table introspection overhead (could cache if needed) to every has_feature() call
  • could introspect table name from model instead of hard-coding
*Originally created by @jnovinger on 10/2/2025* ### Fixes: #20290 In v4.4.0, `ObjectType` became a concrete model with a database table. Signal handlers query this table during migrations, but the table doesn't exist yet during 3.7.x→4.4.0 upgrades. The query failures poison the transaction and abort migrations. This commits adds a `objecttype_table_exists()` helper and and uses it in three places: - `has_feature()` in netbox/models/features.py - `update_object_types()` in core/signals.py - `Search backend cache()` in search/backends.py If `core_objecttype` table doesn't exist, operations return early instead of querying. Once table exists, normal operation resumes. Pros - no migration changes - one helper function, three identical checks - easy to test, verify, and remove later if needed - queries PostgreSQL system catalogs for table existence - won't poison transactions Cons - fixes symptoms, not root cause - touches 3 different files instead of one surgical fix - future code querying `ObjectType` during migrations could still fail/future developers might not know to add this check in new code - adds table introspection overhead (could cache if needed) to every `has_feature()` call - could introspect table name from model instead of hard-coding
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1155