{"record":{"id":"f6d34f46f1b9312e","repo":"pathwaycom/pathway","slug":"default-must-be-of-type-json-none-found-defa","errorCode":null,"errorMessage":"Default must be of type {Json | None}, found {default_dtype.typehint}.","messagePattern":"Default must be of type (.+?), found (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":516,"sourceCode":"        dtypes = tuple(arg._dtype for arg in expression._args)\n        self._check_for_disallowed_types(\"pathway.make_tuple\", *dtypes)\n        return _wrap(expression, dt.Tuple(*dtypes))\n\n    def eval_get(\n        self,\n        expression: expr.GetExpression,\n        state: TypeInterpreterState | None = None,\n        **kwargs,\n    ) -> expr.GetExpression:\n        expression = super().eval_get(expression, state=state, **kwargs)\n        object_dtype = expression._object._dtype\n        index_dtype = expression._index._dtype\n        default_dtype = expression._default._dtype\n\n        if object_dtype == dt.JSON:\n            # json\n            if not dt.dtype_issubclass(default_dtype, dt.Optional(dt.JSON)):\n                raise TypeError(\n                    f\"Default must be of type {Json | None}, found {default_dtype.typehint}.\"\n                )\n            if not expression._check_if_exists or default_dtype == dt.JSON:\n                return _wrap(expression, dt.JSON)\n            else:\n                return _wrap(expression, dt.Optional(dt.JSON))\n        elif object_dtype.equivalent_to(dt.Optional(dt.JSON)):\n            # optional json\n            raise TypeError(f\"Cannot get from {Json | None}.\")\n        else:\n            # sequence\n            if (\n                not isinstance(object_dtype, (dt.Array, dt.Tuple, dt.List))\n                and object_dtype != dt.ANY\n            ):\n                raise TypeError(\n                    f\"Object in {expression!r} has to be a JSON or sequence.\"\n                )","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L498-L534","documentation":"Raised by the type interpreter when a get() (indexing) operation on a Json column is given a default whose dtype is not a subtype of Json | None. On JSON objects, json_col.get(key, default=...) requires the default to be Json-typed (a JSON value) or None; passing an int/str/bool literal default fails because the JSON accessor's default slot must be Json.","triggerScenarios":"pw.this.json_col.get('key', default=0) or default=\"fallback\" on a Json column (plain Python scalars are rejected); defaults coming from another non-Json column; get with check_if_exists semantics where users expect Python dict.get behavior with arbitrary defaults.","commonSituations":"Expecting dict.get(key, 'n/a') semantics with arbitrary defaults; JSON payloads where missing keys should yield a scalar fallback; migrating code that used apply(lambda d: d.get(k, 0)).","solutions":["Wrap the default in pw.Json: pw.this.col.get('key', default=pw.Json(0)) so its dtype is Json","Or use None default and post-process: pw.this.col.get('key', optional=True) then fill/unwrap with the desired scalar","Do custom fallback logic in .apply(lambda d: d.get('key', 0)) where plain Python semantics apply"],"exampleFix":"# before\nv = pw.this.payload.get(\"count\", default=0)  # TypeError: default must be Json | None\n\n# after\nv = pw.this.payload.get(\"count\", default=pw.Json(0))","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\ndef json_default_ok(default) -> bool:\n    return default is None or isinstance(default, pw.Json)\n\n# wrap plain scalars before use\ndef safe_default(v):\n    return v if json_default_ok(v) else pw.Json(v)","typeGuard":"def is_json_or_none(v) -> bool:\n    import pathway as pw\n    return v is None or isinstance(v, pw.Json)","tryCatchPattern":"try:\n    v = pw.this.payload.get(\"k\", default=0)\nexcept TypeError:\n    v = pw.this.payload.get(\"k\", default=pw.Json(0))","preventionTips":["Always wrap get() defaults in pw.Json(...)","Or use default=None and apply the scalar fallback after the get","For arbitrary Python defaults, use .apply(lambda d: d.get(k, default))"],"tags":["pathway","json","get","default-value","typeerror"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}