{"record":{"id":"1f3ab3304646d531","repo":"apache/beam","slug":"cannot-get-a-type-descriptor-for-s","errorCode":null,"errorMessage":"Cannot get a type descriptor for %s.","messagePattern":"Cannot get a type descriptor for (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/internal/gcp/json_value.py","lineNumber":61,"sourceCode":"\n  Returns:\n    A dictionary containing the keys ``@type`` and ``value`` with the value for\n    the ``@type`` of appropriate type.\n\n  Raises:\n    TypeError: if the Python object has a type that is not\n      supported.\n  \"\"\"\n  if isinstance(obj, (bytes, str)):\n    type_name = 'Text'\n  elif isinstance(obj, bool):\n    type_name = 'Boolean'\n  elif isinstance(obj, int):\n    type_name = 'Integer'\n  elif isinstance(obj, float):\n    type_name = 'Float'\n  else:\n    raise TypeError('Cannot get a type descriptor for %s.' % repr(obj))\n  return {'@type': 'http://schema.org/%s' % type_name, 'value': obj}\n\n\ndef to_json_value(obj, with_type=False):\n  \"\"\"For internal use only; no backwards-compatibility guarantees.\n\n  Converts Python objects into extra_types.JsonValue objects.\n\n  Args:\n    obj: Python object to be converted. Can be :data:`None`.\n    with_type: If true then the basic types (``bytes``, ``unicode``, ``int``,\n      ``float``, ``bool``) will be wrapped in ``@type:value`` dictionaries.\n      Otherwise the straight value is encoded into a ``JsonValue``.\n\n  Returns:\n    A ``JsonValue`` object using ``JsonValue``, ``JsonArray`` and ``JsonObject``\n    types for the corresponding values, lists, or dictionaries.\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/internal/gcp/json_value.py#L43-L79","documentation":"get_typed_value_descriptor converts a Python scalar into a schema.org-typed descriptor (Boolean/Integer/Float) for Beam's internal JSON encoding. If the object is not None, str, bytes, bool, int, or float it raises TypeError 'Cannot get a type descriptor for %s' with repr of the offending object.","triggerScenarios":"Calling to_json_value(obj, with_type=True) (which delegates to get_typed_value_descriptor) with an unsupported type such as a list, dict, datetime, Decimal, or custom object; passing a numpy scalar (numpy.float32 is not a Python float and fails isinstance checks).","commonSituations":"Encoding pipeline parameters with composite values while requesting typed output; numpy numeric types that fail isinstance(float); passing enums or dataclasses instead of primitives.","solutions":["Convert the value to a supported primitive before encoding: `float(np_value)`, `str(obj)`, or `json.dumps(obj)` as a string.","Only pass with_type=True for scalar values; encode composites as plain JSON structures.","Check type with isinstance against (bool, int, float, str, bytes) before calling."],"exampleFix":"// before\nto_json_value(np.float32(1.5), with_type=True)  # TypeError\n// after\nto_json_value(float(np.float32(1.5)), with_type=True)","handlingStrategy":"validation","validationCode":"def encodable_with_type(v) -> bool:\n    if v is None: return True\n    return isinstance(v, (str, bytes, bool, int, float))","typeGuard":"def is_schema_typed_scalar(v) -> bool:\n    return v is None or isinstance(v, (str, bytes, bool, int, float))","tryCatchPattern":"try:\n    return to_json_value(v, with_type=True)\nexcept TypeError as e:\n    if 'type descriptor' in str(e):\n        return to_json_value(repr(v))  # fall back to string encoding\n    raise","preventionTips":["Convert numpy scalars to native Python types before encoding.","Only use with_type=True for scalar values.","Coerce datetime/Decimal/custom objects to str or primitives first."],"tags":["python","apache-beam","json","type-error","encoding"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}