keras-team/keras

[Bug] deserialize_keras_object raises AttributeError for invalid config types

Closed

#22,701 opened on Apr 18, 2026

 (6 comments) (0 reactions) (1 assignee)Python (19,747 forks)batch import
Good first issuebackend:tensorflowstat:contributions welcometype:Bug

Repository metrics

Stars
 (64,219 stars)
PR merge metrics
 (Avg merge 6d 23h) (75 merged PRs in 30d)

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