{"record":{"id":"1d9aee3cf4a70eaf","repo":"pathwaycom/pathway","slug":"right-part-of-a-join-condition-has-to-be-a-referen","errorCode":null,"errorMessage":"Right part of a join condition has to be a reference to a table on the right side of a join","messagePattern":"Right part of a join condition has to be a reference to a table on the right side of a join","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/joins.py","lineNumber":1164,"sourceCode":"            + f\"The types are: {eval_type(cond._left)} and {eval_type(cond._right)}. \"\n            + \"You might try casting the respective columns to Any type to circumvent this,\"\n            + \" but this is most probably an error.\"\n        )\n    cond_left = cast(expr.ColumnReference, cond._left)\n    cond_right = cast(expr.ColumnReference, cond._right)\n    if cond_left.table == right and cond_right.table == left:\n        raise ValueError(\n            \"The boolean condition is not properly ordered.\\n\"\n            + \"The left part should refer to left joinable and the right one should refer to the right joinable,\"\n            + \" e.g. t1.join(t2, t1.bar==t2.foo).\"\n        )\n    if cond_left.table != left:\n        raise ValueError(\n            \"Left part of a join condition has to be a reference to a table \"\n            + \"on the left side of a join\"\n        )\n    if cond_right.table != right:\n        raise ValueError(\n            \"Right part of a join condition has to be a reference to a table \"\n            + \"on the right side of a join\"\n        )\n    return cond_left, cond_right, cond\n\n\ndef join(\n    left: Joinable,\n    right: Joinable,\n    *on: expr.ColumnExpression,\n    id: expr.ColumnReference | None = None,\n    how: JoinMode = JoinMode.INNER,\n    left_instance: expr.ColumnReference | None = None,\n    right_instance: expr.ColumnReference | None = None,\n    left_exactly_once: bool = False,\n    right_exactly_once: bool = False,\n) -> JoinResult:\n    \"\"\"Join self with other using the given join expression.","sourceCodeStart":1146,"sourceCodeEnd":1182,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/joins.py#L1146-L1182","documentation":"Final check in validate_join_condition: cond_right.table must equal the right joinable; otherwise ValueError 'Right part of a join condition has to be a reference to a table on the right side of a join'. Catches conditions whose right operand references the left table again or an unrelated table (left-side misuse is caught by 97/98 first).","triggerScenarios":"t1.join(t2, t1.a == t1.b) — both sides reference the left table; or t1.join(t2, t1.a == t3.b).","commonSituations":"Copy-pasting a condition and changing only one side; self-comparisons intended as filters rather than join keys; stale variables after renaming join inputs.","solutions":["Point the right operand at the right joinable: t1.join(t2, t1.a == t2.a)","For a same-table comparison use filter()/where instead of join","Chain joins when more than two tables are involved"],"exampleFix":"# before\nres = t1.join(t2, t1.a == t1.b)\n\n# after\nres = t1.join(t2, t1.a == t2.a)","handlingStrategy":"validation","validationCode":"def right_ref_ok(right, cond) -> bool:\n    return cond._right.table == right\n\nassert right_ref_ok(t2, t1.k == t2.k)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Each side of == must reference its own joinable; same-table comparisons belong in where()/filter()","Chain multi-table joins rather than referencing a third table in one condition"],"tags":["pathway","join","condition","api-misuse"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}