diff --git a/backend/typedb/main.py b/backend/typedb/main.py index 638699fdf3..f1aa06138a 100644 --- a/backend/typedb/main.py +++ b/backend/typedb/main.py @@ -108,10 +108,21 @@ def serialize_concept(concept) -> Dict[str, Any]: if hasattr(concept_type, 'get_label'): label = concept_type.get_label() result['_type'] = label.name if hasattr(label, 'name') else str(label) + result['type'] = result['_type'] # Alias for frontend compatibility if hasattr(concept, 'get_iid'): iid = concept.get_iid() - result['_iid'] = iid.hex() if iid else None + # Handle both old (bytes with .hex()) and new (string) driver formats + if iid is None: + result['_iid'] = None + result['id'] = None + elif hasattr(iid, 'hex'): + result['_iid'] = iid.hex() + result['id'] = iid.hex() + else: + # iid is already a string + result['_iid'] = str(iid) + result['id'] = str(iid) if hasattr(concept, 'get_value'): result['value'] = concept.get_value() @@ -127,8 +138,18 @@ def serialize_concept_map(concept_map) -> Dict[str, Any]: concept = concept_map.get(var) if concept: if hasattr(concept, 'get_value'): - # It's an attribute value - result[var] = concept.get_value() + # It's an attribute value - include type info for frontend + attr_type = None + if hasattr(concept, 'get_type'): + concept_type = concept.get_type() + if hasattr(concept_type, 'get_label'): + label = concept_type.get_label() + attr_type = label.name if hasattr(label, 'name') else str(label) + + result[var] = { + 'value': concept.get_value(), + 'type': attr_type, + } elif hasattr(concept, 'get_iid'): # It's an entity or relation result[var] = serialize_concept(concept)