{"record":{"id":"2e316b5c6a8ae7ea","repo":"boto/boto3","slug":"cannot-inject-class-attribute-name-attribute","errorCode":null,"errorMessage":"Cannot inject class attribute \"{name}\", attribute already exists in class dict.","messagePattern":"Cannot inject class attribute \"(.+?)\", attribute already exists in class dict\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"boto3/utils.py","lineNumber":64,"sourceCode":"\n    pass\n\n\ndef lazy_call(full_name, **kwargs):\n    parent_kwargs = kwargs\n\n    def _handler(**kwargs):\n        module, function_name = full_name.rsplit('.', 1)\n        module = import_module(module)\n        kwargs.update(parent_kwargs)\n        return getattr(module, function_name)(**kwargs)\n\n    return _handler\n\n\ndef inject_attribute(class_attributes, name, value):\n    if name in class_attributes:\n        raise RuntimeError(\n            f'Cannot inject class attribute \"{name}\", attribute '\n            f'already exists in class dict.'\n        )\n    else:\n        class_attributes[name] = value\n\n\nclass LazyLoadedWaiterModel:\n    \"\"\"A lazily loaded waiter model\n\n    This does not load the service waiter model until an attempt is made\n    to retrieve the waiter model for a specific waiter. This is helpful\n    in docstring generation where we do not need to actually need to grab\n    the waiter-2.json until it is accessed through a ``get_waiter`` call\n    when the docstring is generated/accessed.\n    \"\"\"\n\n    def __init__(self, bc_session, service_name, api_version):","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/boto/boto3/blob/6e10b029c1326a437932a8b24f38af69fd986e15/boto3/utils.py#L46-L82","documentation":"`inject_attribute` is used during resource class generation to attach extra attributes (like `meta`, identifiers, or lazy-loaded properties) to a resource class's `class_attributes` dict. It refuses to overwrite an existing key to prevent silently shadowing a real method/attribute. A collision means the resource model defines an identifier, attribute, or action whose name clashes with something already declared on the class (e.g. a Python keyword, a reserved member like `meta`, or two model elements with the same name).","triggerScenarios":"Generated resource class construction for a service whose `resources-1.json` declares two elements that resolve to the same Python name, or a name that collides with a base/reserved attribute (`meta`, `wait`, `load`, `reload`, a Python dunder). Surfaced on the first `boto3.resource(service)` instantiation that builds that class.","commonSituations":"A new API/model file introduced a name collision not yet fixed in your boto3 version; a locally patched resource model; running a beta/patched boto3 build; in rare cases, a service added a member whose name (after snake_case conversion) matches an existing one.","solutions":["Upgrade boto3/botocore to a release where the model collision is resolved.","Reinstall boto3 cleanly (`pip install --force-reinstall boto3`) to rule out a corrupt or patched data file.","Remove any local monkey-patches or edited `resources-1.json` files that may have introduced the duplicate name.","Report the collision (service + resource + attribute name) to the boto3 maintainers with the installed versions."],"exampleFix":"# before: collision inside the bundled model for service X\nimport boto3\nboto3.resource('svc-with-collision')  # RuntimeError: Cannot inject class attribute \"...\"\n\n# after\npip install -U boto3 botocore   # pick a release that fixed the model","handlingStrategy":"type-guard","validationCode":"import boto3\ndef resource_loads(service):\n    try:\n        boto3.resource(service)\n        return True\n    except RuntimeError:\n        return False\n\n# fail fast at startup so you can flag a reinstall instead of crashing later","typeGuard":"def model_collision_free(session, service) -> bool:\n    try:\n        session.resource(service)\n        return True\n    except RuntimeError:\n        return False","tryCatchPattern":"try:\n    handle = boto3.resource(service)\nexcept RuntimeError as e:\n    if 'Cannot inject class attribute' in str(e):\n        handle = boto3.client(service)  # fall back to low-level client","preventionTips":["Keep boto3/botocore on a current, compatible pair.","Avoid patching resource model JSON files locally.","Add startup smoke-tests for every resource you depend on."],"tags":["resource-model","internal","name-collision","installation"],"backgroundTag":null,"analyzedSha":"6e10b029c1326a437932a8b24f38af69fd986e15","analyzedAt":"2026-08-11T20:52:47.213Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}