AttributeError: Object Missing Instance Attribute

AttributeError: 'MyClass' object has no attribute 'value'

Quick Answer

You are accessing an attribute that was never set on the instance. Make sure the attribute is initialized in __init__ with self.attribute, not just a local variable.

Why This Happens

Instance attributes are created by assignment with self.attr = value in __init__. If you forget self, you create a local variable. If __init__ conditionally sets attributes, some instances may lack them.

The Problem

class Counter:
    def __init__(self, start):
        count = start  # Missing self!

    def increment(self):
        self.count += 1

The Fix

class Counter:
    def __init__(self, start):
        self.count = start

    def increment(self):
        self.count += 1

Step-by-Step Fix

  1. 1

    Check __init__ for self

    Verify all attribute assignments use self.attribute = value.

  2. 2

    Check for typos

    Ensure the attribute name in __init__ matches the name used elsewhere.

  3. 3

    Initialize all attributes

    Set default values for all attributes in __init__.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free