Fix JSON serialization error in get_installed_apps() #722

Closed
opened 2026-04-05 17:18:39 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @dantte-lp on 12/16/2025

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.

*Originally created by @dantte-lp on 12/16/2025* ### 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.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#722