Last modified: Dec 12, 2025 By Alexander Williams

Fix AttributeError: 'dict' object has no attribute 'update'

You see a confusing error. Python says a dict has no update. This seems wrong. Dictionaries have the update method. The error means your variable is not a dict. It is another type. This is a common Python mistake.

This article explains the error. You will learn why it happens. We will show you how to fix it. We will also cover best practices to avoid it.

Understanding the Error Message

The error is clear. An AttributeError occurred. It says a 'dict' object has no attribute 'update'. This is confusing. The update method exists for dictionaries.

The key is the first part. Python tells you the object's type. It says 'dict' object. But this is misleading. Your variable is likely not a dictionary.

Python is telling you the object's type. It is the type it found when the error happened. The object might be a list or a string. It is not a real dict.

Why This Error Happens

The main cause is simple. You try to call .update() on a non-dictionary. Your variable might have been reassigned. Or a function returned a different type.

Another common cause is variable shadowing. You might have a variable named 'dict'. This overwrites the built-in type. Then you try to use it as a dictionary.

Let's look at a code example that causes the error.


# Example causing the error
my_data = [{'a': 1}, {'b': 2}]  # This is a LIST of dicts
print(type(my_data))  # Check the type

# Trying to call .update() on the LIST causes the error
my_data.update({'c': 3})

<class 'list'>
Traceback (most recent call last):
  File "script.py", line 6, in <module>
    my_data.update({'c': 3})
AttributeError: 'list' object has no attribute 'update'

See the output. The type of my_data is 'list'. The error message says 'list' object. Our article title error said 'dict'. The principle is the same. The variable is not what you think.

How to Diagnose the Problem

First, check the variable's type. Use the type() function. Or use print() to see its value. This reveals its true nature.


problem_var = "get_data"  # This is a string!
print(f"Type: {type(problem_var)}")
print(f"Value: {problem_var}")

# This will fail
problem_var.update({"key": "value"})

Second, trace the variable's origin. Did it come from a function? Check the function's return value. It might not return a dict.

Third, look for variable name conflicts. Avoid using names like 'dict', 'list', or 'str'. These are built-in types. Using them can cause confusion.

Common Scenarios and Fixes

Scenario 1: Variable is a List of Dictionaries

You have a list containing dicts. You try to update the list. You need to update a specific dictionary inside the list.


# Broken Code
data_list = [{'name': 'Alice'}, {'name': 'Bob'}]
data_list.update({'age': 30})  # ERROR: Can't update a list

# Fixed Code
# Update the first dictionary in the list
data_list[0].update({'age': 30})
print(data_list)

[{'name': 'Alice', 'age': 30}, {'name': 'Bob'}]

You accessed the dict at index 0. Then you called update on it. This works. For related list errors, see Fix Python AttributeError: 'list' object has no attribute 'update'.

Scenario 2: Variable is a String

Your variable holds a string. Maybe from user input or a file. You cannot update a string. Strings are immutable.


# Broken Code
user_input = input("Enter config: ")  # Returns a string
# Let's say user enters '{"mode": "test"}'
# user_input is a str, not a dict
user_input.update({"version": 2})  # ERROR

# Fixed Code
import json
user_input = input("Enter config: ")
try:
    config_dict = json.loads(user_input)  # Convert string to dict
    config_dict.update({"version": 2})
    print("Updated config:", config_dict)
except json.JSONDecodeError:
    print("Invalid JSON entered.")

We used json.loads() to parse the string. This converts it to a dictionary. Now update works. For string attribute errors, read Fix AttributeError: 'str' object has no attribute 'update'.

Scenario 3: Variable is None

A function may return None on failure. Your variable becomes None. Calling .update() on None causes this error.


def get_user_data(user_id):
    # Simulating a failed lookup
    return None

# Broken Code
data = get_user_data(999)
data.update({"active": True})  # ERROR: 'NoneType' object has no attribute 'update'

# Fixed Code
data = get_user_data(999)
if isinstance(data, dict):
    data.update({"active": True})
else:
    data = {"active": True}  # Initialize a new dict
print(data)

Always check if your variable is a dict before calling dict methods. Use isinstance() or check for None.

Scenario 4: Overwriting the 'dict' Name

You used 'dict' as a variable name. This shadows the built-in class. Later, you try to create a dictionary.


# Broken Code
dict = {"old": "value"}  # BAD: Overwrites the built-in 'dict'
new_dict = dict(new="key")  # This tries to call your variable as a function
new_dict.update({"a": 1})   # This line might fail in complex ways

# Fixed Code
# Never use built-in names as variables
my_dict = {"old": "value"}
new_dict = dict(new="key")  # Now this correctly uses the built-in dict()
new_dict.update({"a": 1})
print(new_dict)

Avoid using dict, list, str as variable names. This prevents many hidden bugs.

Best Practices to Avoid the Error

Use type hints. They make your code's intent clear. They help IDEs warn you of type mismatches.


from typing import Dict, Optional

def process_config(config: Optional[Dict]) -> Dict:
    """Process a configuration dictionary."""
    if config is None:
        config = {}  # Initialize a new dict
    config.update({"processed": True})
    return config

Validate data early. Check types when receiving data from external sources. Use try-except blocks for safety.

Use descriptive variable names. Names like user_dict or config_list are helpful. They remind you of the data type.

For other common dictionary method mix-ups, you might encounter errors like Fix Python AttributeError 'dict' object has no attribute 'append'.

Conclusion

The AttributeError about 'dict' and 'update' is a type error. Your variable is not a dictionary. Use type() to inspect it. Find where it got the wrong value.

Common fixes include indexing into a list. Or parsing a JSON string. Or handling None values. Always ensure your variable is a dict before using dict methods.

Follow good naming practices. Use type hints. Validate your data. These steps will prevent this error. They will make your Python code more robust and clear.