Skip to content

Don't crash host pages when a custom object field changed since startup - #24

Open
Kani999 wants to merge 1 commit into
masterfrom
fix/stale-field-badge-crash
Open

Kani999 wants to merge 1 commit into
masterfrom
fix/stale-field-badge-crash

Conversation

@Kani999

@Kani999 Kani999 commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Typed tabs save field names (field_infos) at ready(). When a Custom Object Type field is deleted or renamed after startup, those names no longer exist on the live dynamic model. The badge renders on every host detail page, so the stale names took down all of them:

 _badge(instance)
-  total = dynamic_model.objects.filter(q_filter).distinct().count()   # FieldError → 500
+  try: total = ...filter(q_filter).distinct().count()
+  except FieldError: log warning, return None                        # tab hidden
 _TypedTabView.get()
-  base_qs = dynamic_model.objects.filter(q_filter).distinct()        # FieldError → 500
+  try: base_qs = ...
+  except FieldError: base_qs = dynamic_model.objects.none()          # empty table

Evidence

  • Before: every Device page →
    FieldError: Cannot resolve keyword 'device' into field. Choices are: bookmarks, contacts, created, id, ...
    at views/typed.py:239 in _badge. Hit in the netbox-authorized-keys test suite (fresh DB, no custom object fields).
    After: new test test_returns_none_when_field_no_longer_exists: filter() raises FieldError → badge returns None. pytest tests/ 37 passed, ruff clean.

Merge Danger

Door: two-way

No models or migrations. Rollback = pin 3.0.0.

Blast Radius: tabs

Affected types keep a hidden tab and an empty table until NetBox restarts, which re-reads the fields. A warning is logged each time.

Typed tabs snapshot field names at ready(). After a field is deleted or
renamed, the badge's .filter() raised FieldError on every detail page of
the referenced model (e.g. all Device pages). Catch it in the badge (hide
the tab) and in the tab view (empty table).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant