{"record":{"id":"5f9dd828ee0225fd","repo":"apache/beam","slug":"type-self-name-object-has-no-attribute-name","errorCode":null,"errorMessage":"'{type(self).__name__}' object has no attribute '{name}'","messagePattern":"'(.+?)' object has no attribute '(.+?)'","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/anomaly/specifiable.py","lineNumber":373,"sourceCode":"\n      For instances of the `Specifiable` class, initialization is deferred\n      (lazy initialization). This function forces the execution of the\n      original `__init__` method using the arguments captured during\n      the object's initial instantiation.\n      \"\"\"\n      self._in_init = True\n      original_init(self, **self.init_kwargs)\n      self._in_init = False\n      self._initialized = True\n\n    # __getattr__ is only called when an attribute is not found in the object\n    def new_getattr(self, name):\n      logging.debug(\n          \"Trying to access %s.%s, but it is not found.\", class_name, name)\n\n      # Fix the infinite loop issue when pickling a Specifiable\n      if name in [\"_in_init\", \"__getstate__\"] and name not in self.__dict__:\n        raise AttributeError(\n            f\"'{type(self).__name__}' object has no attribute '{name}'\")\n\n      # If the attribute is not found during or after initialization, then\n      # it is a missing attribute.\n      if self._in_init or self._initialized:\n        raise AttributeError(\n            f\"'{type(self).__name__}' object has no attribute '{name}'\")\n\n      # Here, we know the object is not initialized, then we will call original\n      # init method.\n      logging.debug(\"Call original %s.__init__ in new_getattr\", class_name)\n      run_original_init(self)\n\n      # __getattribute__ is call for every attribute regardless whether it is\n      # present in the object. In this case, we don't cause an infinite loop\n      # if the attribute does not exist.\n      logging.debug(\n          \"Call original %s.__getattribute__(%s) in new_getattr\",","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/anomaly/specifiable.py#L355-L391","documentation":"Specifiable installs a custom __getattr__ (new_getattr) to lazily run the original __init__ when attributes are missing. For pickling-related names (_in_init, __getstate__) that are absent from the instance dict, it raises AttributeError immediately to avoid infinite recursion.","triggerScenarios":"Pickling or copying a Specifiable instance before its lazy init has populated _in_init/__getstate__ in __dict__ (e.g. deepcopy, multiprocessing spawn, Beam workers serializing the object).","commonSituations":"Submitting a Beam pipeline where the detector is pickled before __init__ ran; using copy.deepcopy on a not-yet-initialized Specifiable; custom __reduce__/__getstate__ implementations interacting with the wrapper.","solutions":["Ensure the object is initialized (access any attribute or call run_original_init path) before pickling","Avoid pickling the bare wrapper; serialize its spec via to_spec() and reconstruct from_spec on the other side","Upgrade Beam — later versions refine this pickling workaround"],"exampleFix":"// before\npickle.dumps(detector)  # AttributeError on _in_init\n\n// after\nspec = detector.to_spec()\ndata = specifiable.spec_to_json(spec)\n# later: detector = specifiable.spec_to_specifiable(specifiable.json_to_spec(data))","handlingStrategy":"try-catch","validationCode":"if not getattr(detector, '_initialized', True):\n    # force lazy init before pickling\n    _ = detector.__dict__","typeGuard":null,"tryCatchPattern":"try:\n    payload = pickle.dumps(detector)\nexcept AttributeError:\n    payload = specifiable.spec_to_json(detector.to_spec())","preventionTips":["Initialize Specifiable objects before serializing","Prefer spec-based (to_spec/spec_to_specifiable) serialization for Beam workers","Test pickling of pipeline components locally before submitting"],"tags":["python","apache-beam","pickle","attributeerror"],"backgroundTag":"attribute-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}