{"record":{"id":"16f5a6429d24c3c4","repo":"pathwaycom/pathway","slug":"creating-a-reference-to-a-class-arg-table-defined","errorCode":null,"errorMessage":"creating a reference to a class_arg table defined for another transformer","messagePattern":"creating a reference to a class_arg table defined for another transformer","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/row_transformer.py","lineNumber":141,"sourceCode":"            if isinstance(attr, AbstractOutputAttribute)\n        }\n\n    def _is_attribute(self, col_name: str) -> bool:\n        return col_name in self._attributes\n\n    def _get_attribute(self, col_name: str) -> AbstractAttribute:\n        return self._attributes[col_name]\n\n    def _get_class_property(self, name: str) -> Any:\n        assert name not in self._attributes\n        return inspect.getattr_static(self, name)\n\n    def __set_name__(self, owner, name):\n        self.name: str = name\n\n    def __call__(self, ref: RowReference, ptr: Pointer) -> RowReference:  # type: ignore\n        if ref._class_arg.transformer != self.transformer:\n            raise ValueError(\n                \"creating a reference to a class_arg table defined for another transformer\"\n            )\n\n        return ref._with_class_arg(self, ptr)\n\n\nclass ClassArg(metaclass=ClassArgMeta):\n    \"\"\"Base class to inherit from when writing inner classes for class transformers.\"\"\"\n\n    transformer: RowTransformer  # stub for mypy\n    id: Pointer  # stub for mypy\n\n    def pointer_from(self, *args, optional=False) -> Pointer:\n        \"\"\"Pseudo-random hash of its argument. Produces pointer types. Applied value-wise.\"\"\"\n        return ref_scalar(*args, optional=optional)\n\n    def __init_subclass__(\n        cls,","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/row_transformer.py#L123-L159","documentation":"In Pathway class transformers (@pw.row_transformer classes), a class_arg attribute (a table defined inside one transformer class) can only be referenced from RowReferences belonging to the same transformer. RowReferenceClassArg.__call__ checks ref._class_arg.transformer != self.transformer and rejects mixing a RowReference from transformer A with a class_arg (pointer method) from transformer B.","triggerScenarios":"Calling a method defined as class_arg in transformer X on a RowReference that originates from transformer Y, e.g. inside row_transformer methods: other_transformer.table_method(ref) where ref comes from a different transformer's context, or reusing a stored class_arg across transformer instances.","commonSituations":"Refactoring shared logic between two row transformers and moving a method to the wrong class; passing RowReference objects between transformers as if they were plain rows.","solutions":["Keep each class_arg inside the transformer whose rows it operates on; duplicate or move the method into the transformer that supplies the RowReference.","If logic must be shared, factor it into a plain function taking the extracted column values, not a class_arg.","Ensure you instantiate/reference the class_arg through the same transformer class (ClassName.method(ref)) that produced ref."],"exampleFix":"# before\n@pw.row_transformer\nclass A:\n    class input(pw.ClassArg): ...\n    class lookup(pw.ClassArg, id_from=input): ...\n\n@pw.row_transformer\nclass B:\n    class input(pw.ClassArg):\n        def enrich(self, ref):\n            return A.lookup(ref)  # ref belongs to B -> error\n\n# after\n@pw.row_transformer\nclass B:\n    class input(pw.ClassArg): ...\n    class lookup(pw.ClassArg, id_from=input): ...  # local lookup\n\n    def enrich(...)  # use B.lookup(ref)","handlingStrategy":"type-guard","validationCode":"def same_transformer(ref, class_arg) -> bool:\n    return ref._class_arg.transformer is class_arg.transformer","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass RowReference objects between transformer classes; extract values first.","Keep each class_arg/lookup table inside the transformer that owns its rows."],"tags":["pathway","row-transformer","class-arg","api-misuse"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}