{"record":{"id":"b313fde963c66b0b","repo":"jax-ml/jax","slug":"self-class-name-has-no-attribute-name-b313fd","errorCode":null,"errorMessage":"{self.__class__.__name__} has no attribute {name}","messagePattern":"(.+?) has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":1190,"sourceCode":"    # if the aval property raises an AttributeError, gets caught here\n    assert not config.enable_checks.value or name != \"aval\"\n\n    # These must raise AttributeError in the base class for backward compatibility.\n    # TODO(jakevdp): can we change this and make them raise NotImplementedError instead?\n    if name in [\"block_until_ready\", \"copy_to_host_async\"]:\n      raise AttributeError(\n        f\"The '{name}' method is not available on {self._error_repr()}.\"\n        f\"{self._origin_msg()}\")\n\n    if name == 'sharding':\n      raise AttributeError(\n        f\"The 'sharding' attribute is not available on {self._error_repr()}. \"\n        \"To query sharding information on tracers, use `jax.typeof(x)`.\")\n\n    try:\n      attr = getattr(self.aval, name)\n    except AttributeError as err:\n      raise AttributeError(\n          f\"{self.__class__.__name__} has no attribute {name}\"\n      ) from err\n    else:\n      t = type(attr)\n      if t is aval_property:\n        return attr.fget(self)\n      elif t is aval_method:\n        return types.MethodType(attr.fun, self)\n      else:\n        return attr\n\n  def _short_repr(self) -> str:\n    return f'{self.__class__.__name__}<{self.aval}>'\n\n  def _pretty_print(self, verbose: bool = False) -> pp.Doc:\n    if not verbose:\n      return pp.text(self._short_repr())\n","sourceCodeStart":1172,"sourceCodeEnd":1208,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L1172-L1208","documentation":"Raised by Tracer.__getattr__ in JAX when you access an attribute that exists neither on the Tracer itself nor on the underlying abstract value (aval). JAX tracers only forward a fixed set of attributes from the aval; anything else (including array-only attributes like 'sharding', as the adjacent code notes) is rejected with AttributeError so transformations stay traceable. The chained 'from err' preserves the original AttributeError from the aval lookup.","triggerScenarios":"Accessing an arbitrary attribute on a JAX-traced value inside jit/pmap/grad/vmap/scan, e.g. `x.sharding`, `x.some_custom_field`, or a typo like `x.shappe` where x is a Tracer. Also calling getattr(x, name) on a tracer for names not present on AbstractValue.","commonSituations":"Refactoring code that operated on concrete jax.Arrays into a jitted function; using NumPy-style attributes or custom attributes on arrays that don't exist on tracers; typos in attribute names that only surface under tracing; relying on x.sharding inside jit (JAX explicitly points you to jax.typeof).","solutions":["Read the chained original error and the traceback to identify which attribute name was requested and on which tracer.","If the attribute is only meaningful for materialized arrays (e.g. sharding, device, addressable_data), move that access outside the traced function or compute it before jit.","If it's a typo, fix the attribute name; compare with the attribute list of the concrete array type you intended.","Replace runtime introspection with jax.typeof(x) or the tracer's aval (x.aval) for shape/dtype/sharding info inside traces.","Refactor the function so host-side Python logic (attribute checks) is not applied to traced values; use static arguments or pytrees instead of duck-typed attributes."],"exampleFix":"// before\n@jax.jit\ndef f(x):\n    return x.sharding   # AttributeError: JVPTracer has no attribute sharding\n\n// after\n@jax.jit\ndef f(x):\n    print(jax.typeof(x))  # inspect abstract info instead\n    return x * 2","handlingStrategy":"type-guard","validationCode":"import jax\n\ndef safe_getattr_traced(x, name, default=None):\n    if isinstance(x, jax.core.Tracer):\n        allowed = {'dtype','shape','ndim','size','weak_type','named_shape'}\n        if name not in allowed:\n            return default\n    return getattr(x, name, default)","typeGuard":"from jax.core import Tracer\n\ndef is_tracer(x) -> bool:\n    return isinstance(x, Tracer)\n\ndef has_aval_attr(x, name) -> bool:\n    return hasattr(getattr(x, 'aval', x), name)","tryCatchPattern":"try:\n    attr = getattr(x, name)\nexcept AttributeError as e:\n    if 'has no attribute' in str(e) and isinstance(x, jax.core.Tracer):\n        # attribute is array-only / misspelled; take host-side path\n        attr = None\n    else:\n        raise","preventionTips":["Keep attribute introspection of arrays out of jitted/transformed functions.","Prefer jax.typeof(x) or x.aval for shape/dtype/sharding info inside traces.","Lint traced code for non-allowlisted attribute access on arguments.","Run small smoke tests through the same transforms your production path uses."],"tags":["jax","tracer","attributeerror","jit","duck-typing"],"backgroundTag":"jax-tracer-attribute-error","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}