{"record":{"id":"795652c1c80a87c8","repo":"dagger/dagger","slug":"transform-error-e-failed-to-instantiate-parent","errorCode":null,"errorMessage":"{transform_error(e, \"Failed to instantiate parent object '{obj_type}'\")}\nThis could be an error in the Python SDK. If so, please file a bug report.","messagePattern":"(.+?)'\"\\)\\}\nThis could be an error in the Python SDK\\. If so, please file a bug report\\.","errorType":"exception","errorClass":"InvalidInputError","httpStatus":null,"severity":"error","filePath":"sdk/python/src/dagger/mod/_module.py","lineNumber":513,"sourceCode":"            return await self.structure(state, obj_type.cls)\n        except Exception as e:\n            log_exception_only(e, \"Failed to instantiate parent object\")\n            msg = transform_error(\n                e,\n                f\"Failed to instantiate parent object '{obj_type}'\",\n                origin=obj_type.cls,\n                typ=obj_type.cls,\n            )\n            # If API is able to make the call this is likely a bug in the SDK.\n            # For example, if the registration phase reports a type that isn't\n            # compatible with cattrs' converter.\n            msg += (\n                \"\\n\"\n                \"This could be an error in the Python SDK. \"\n                \"If so, please file a bug report.\"\n            )\n            extra = {\"object_state\": state}\n            raise InvalidInputError(msg, extra=extra) from e\n\n    async def _convert_inputs(\n        self,\n        fn: Function,\n        inputs: Mapping[APIName, Any],\n    ) -> Mapping[PythonName, Any]:\n        \"\"\"Convert arguments from lower level primitives to the expected types.\"\"\"\n        kwargs = {}\n\n        # Convert arguments to the expected type.\n        for python_name, param in fn.parameters.items():\n            if param.name not in inputs:\n                if not param.is_optional:\n                    msg = f\"Missing required function argument '{python_name}'\"\n                    raise InvalidInputError(msg)\n\n                if param.has_default:\n                    continue","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/sdk/python/src/dagger/mod/_module.py#L495-L531","documentation":"Before invoking a method, the SDK instantiates the parent object by structuring the engine-provided `state` (its field values) into the object's class via cattrs (`structure(state, obj_type.cls)`). Any failure there is wrapped as `InvalidInputError` with a `transform_error` message and the note 'This could be an error in the Python SDK. If so, please file a bug report.', because the API supposedly validated these values against the registered schema — a mismatch usually indicates registration/serialization drift.","triggerScenarios":"Calling a method on an object whose stored fields can't be structured into the declared dataclass: a field's registered type is incompatible with cattrs (e.g. unsupported generic/union), the field's Python type changed after the value was stored, or a required field is absent from the state.","commonSituations":"Using exotic types in `@dagger.object_type` fields that pass registration but fail cattrs unstructure/structure round-trips; changing a field's annotation while old state persists; SDK bugs with certain Optional/generic field combos — hence the bug-report hint.","solutions":["Read the transformed message: it names the field and expected type that failed to structure, plus `object_state` in the extra details.","Simplify or align the object's field annotations with Dagger-supported types (scalars, lists, Optional, other object types, enums).","Round-trip: make sure the field type used at registration is identical to the current class annotation; redeploy the module so registration is refreshed.","If types look right, try a minimal repro and file a bug at dagger/dagger — the message explicitly suggests an SDK bug.","Update the Python SDK to the latest version; several cattrs-related structuring bugs have been fixed over time."],"exampleFix":"# before\n@dagger.object_type\nclass Cache:\n    data: dict  # bare dict may fail cattrs structuring of state\n\n# after\n@dagger.object_type\nclass Cache:\n    data: dict[str, str]","handlingStrategy":"validation","validationCode":"import dataclasses\n\ndef validate_fields(cls) -> list[str]:\n    bad = []\n    for f in dataclasses.fields(cls):\n        t = f.type\n        if isinstance(t, str):\n            bad.append(f\"{f.name}: string annotation '{t}' may not structure\")\n    return bad\n# run at module load: print(validate_fields(MyObject))","typeGuard":null,"tryCatchPattern":"try:\n    res = await session.call_fn(\"MyObject.method\", parent_state={...})\nexcept dagger.InvalidInputError as e:\n    if \"Failed to instantiate parent object\" in str(e):\n        logger.error(\"state incompatible with class: %s state=%s\", e, e.extra.get(\"object_state\"))","preventionTips":["Use only Dagger-supported field types (scalars, list, Optional, enums, object types) in object_type classes","Keep field annotations concrete (dict[str, str], not bare dict)","Update the Python SDK regularly; report genuine structuring bugs to dagger/dagger as the message suggests","Redeploy the module after any field type change so stored state and schema stay in sync"],"tags":["python","dagger-sdk","cattrs","serialization","parent-instantiation"],"backgroundTag":"object-state-structuring-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}