[PR #20473] [CLOSED] RFC: Fixes #20290: Prevent ObjectType queries when table doesn't exist #15935

Closed
opened 2025-12-30 00:24:53 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20473
Author: @jnovinger
Created: 10/2/2025
Status: Closed

Base: mainHead: 20290-non-migration-fix


📝 Commits (1)

  • 52d9904 Fixes #20290: Prevent ObjectType queries when table doesn't exist

📊 Changes

4 files changed (+28 additions, -0 deletions)

View changed files

📝 netbox/core/signals.py (+5 -0)
📝 netbox/netbox/models/features.py (+5 -0)
📝 netbox/netbox/search/backends.py (+5 -0)
📝 netbox/utilities/object_types.py (+13 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20473 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 10/2/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `20290-non-migration-fix` --- ### 📝 Commits (1) - [`52d9904`](https://github.com/netbox-community/netbox/commit/52d990463f43291b7fe95957c70090d282cd628e) Fixes #20290: Prevent ObjectType queries when table doesn't exist ### 📊 Changes **4 files changed** (+28 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `netbox/core/signals.py` (+5 -0) 📝 `netbox/netbox/models/features.py` (+5 -0) 📝 `netbox/netbox/search/backends.py` (+5 -0) 📝 `netbox/utilities/object_types.py` (+13 -0) </details> ### 📄 Description ### 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:53 +01:00
adam closed this issue 2025-12-30 00:24:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15935