Skip to content

Conversation

@dantte-lp
Copy link

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.

Skip non-serializable VERSION attributes when building the installed
apps dictionary for /api/status/. Some packages using setuptools-scm
define VERSION as a type placeholder (e.g., `object`) at runtime rather
than an actual version tuple or string, causing "Object of type type is
not JSON serializable" errors.

This change adds a check to skip any VERSION value that is neither a
tuple nor a string, preventing serialization failures while still
correctly handling standard version formats.
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.

/api/status/ returns JSON serialization error with django-health-check installed

1 participant