keras-team/keras

[Bug] deserialize_keras_object raises AttributeError for invalid config types

Open

#22701 opened on Apr 18, 2026

View on GitHub
 (6 comments) (0 reactions) (1 assignee)Python (64,067 stars) (19,774 forks)batch import
Good first issuebackend:tensorflowstat:contributions welcometype:Bug

Description

Description

deserialize_keras_object may raise AttributeError when provided with invalid config types (e.g., list or string), indicating that input validation occurs after internal method calls.

Reproduction Script

import os
os.environ["KERAS_BACKEND"] = "tensorflow"

from keras.saving import deserialize_keras_object

config = {
    "class_name": "Dense",
    "module": "keras.layers",
    "config": [1, 2, 3]   # invalid type
}

try:
    deserialize_keras_object(config)
except Exception as e:
    print("Exception type:", type(e).__name__)
    print("Message:", e)

Observed behavior

  • Raises AttributeError: 'list' object has no attribute 'get'

Expected behavior

  • Should raise a clear ValueError or TypeError for invalid input structure

Notes

This suggests input validation happens too late and exposes internal implementation details.

Contributor guide