[PR #20994] [CLOSED] Fix JSON serialization error in get_installed_apps() #16113

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20994
Author: @dantte-lp
Created: 12/16/2025
Status: Closed

Base: mainHead: fix/skip-non-serializable-app-versions


📝 Commits (1)

  • d059993 Fix JSON serialization error in get_installed_apps()

📊 Changes

1 file changed (+3 additions, -0 deletions)

View changed files

📝 netbox/utilities/apps.py (+3 -0)

📄 Description

Fixes: #20993

Summary

This PR adds a defensive check in get_installed_apps() to skip VERSION attributes that are neither tuples nor strings, preventing JSON serialization errors in the /api/status/ endpoint.

The Problem:

Some packages (like django-health-check using setuptools-scm) define their VERSION attribute as a type placeholder at runtime rather than an actual version value:

# In django-health-check's _version.py (generated by setuptools-scm)
VERSION_TUPLE: Tuple[int, int, int] = object  # This is <class 'object'> at runtime!

When get_installed_apps() encounters this, it includes <class 'object'> in the dictionary, which fails JSON serialization.

The Fix:

Add an elif branch to skip non-serializable version types:

if type(version) is tuple:
    version = '.'.join(str(n) for n in version)
elif not isinstance(version, str):
    # Skip non-serializable version types (e.g. setuptools-scm placeholders)
    continue

This is a minimal, defensive change that:

  • Maintains existing behavior for tuple and string versions
  • Gracefully handles edge cases from third-party packages
  • Has no impact on correctly-behaving packages

Testing:

Verified fix resolves the issue with django-health-check 3.20.0 installed.


🔄 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/20994 **Author:** [@dantte-lp](https://github.com/dantte-lp) **Created:** 12/16/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/skip-non-serializable-app-versions` --- ### 📝 Commits (1) - [`d059993`](https://github.com/netbox-community/netbox/commit/d0599930efcfd677e3445503a0b0eb80f8f58de2) Fix JSON serialization error in get_installed_apps() ### 📊 Changes **1 file changed** (+3 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `netbox/utilities/apps.py` (+3 -0) </details> ### 📄 Description ### Fixes: #20993 ### Summary This PR adds a defensive check in `get_installed_apps()` to skip VERSION attributes that are neither tuples nor strings, preventing JSON serialization errors in the `/api/status/` endpoint. **The Problem:** Some packages (like `django-health-check` using `setuptools-scm`) define their `VERSION` attribute as a type placeholder at runtime rather than an actual version value: ```python # In django-health-check's _version.py (generated by setuptools-scm) VERSION_TUPLE: Tuple[int, int, int] = object # This is <class 'object'> at runtime! ``` When `get_installed_apps()` encounters this, it includes `<class 'object'>` in the dictionary, which fails JSON serialization. **The Fix:** Add an `elif` branch to skip non-serializable version types: ```python if type(version) is tuple: version = '.'.join(str(n) for n in version) elif not isinstance(version, str): # Skip non-serializable version types (e.g. setuptools-scm placeholders) continue ``` This is a minimal, defensive change that: - Maintains existing behavior for tuple and string versions - Gracefully handles edge cases from third-party packages - Has no impact on correctly-behaving packages **Testing:** Verified fix resolves the issue with `django-health-check` 3.20.0 installed. --- <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:25:52 +01:00
adam closed this issue 2025-12-30 00:25:52 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16113