alibaba / GraphScope

🔨 🍇 💻 🚀 GraphScope: A One-Stop Large-Scale Graph Computing System from Alibaba | 一站式图计算系统
https://graphscope.io
Apache License 2.0
3.26k stars 442 forks source link

[BUG] VarChar type can not be correctly deserialized from python dict #3913

Closed zhanglei1949 closed 1 month ago

zhanglei1949 commented 3 months ago

When construct PropertyType from the following json/dict,

"property_type": {"string": {"var_char": {"max_length": 64}}}

interactive python sdk throw error:

Traceback (most recent call last):
  File "/Users/xiaolei.zl/lei/work/github/GraphScope-flex/GraphScope/charts/graphscope-interactive/script/create_graph.py", line 233, in <module>
    graph_id = create_graph(sess)
               ^^^^^^^^^^^^^^^^^^
  File "/Users/xiaolei.zl/lei/work/github/GraphScope-flex/GraphScope/charts/graphscope-interactive/script/create_graph.py", line 182, in create_graph
    graph_id = sess.create_graph(CreateGraphRequest.from_dict(huoyan_graph))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_graph_request.py", line 102, in from_dict
    "schema": CreateGraphSchemaRequest.from_dict(obj["schema"]) if obj.get("schema") is not None else None
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_graph_schema_request.py", line 101, in from_dict
    "vertex_types": [CreateVertexType.from_dict(_item) for _item in obj["vertex_types"]] if obj.get("vertex_types") is not None else None,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_graph_schema_request.py", line 101, in <listcomp>
    "vertex_types": [CreateVertexType.from_dict(_item) for _item in obj["vertex_types"]] if obj.get("vertex_types") is not None else None,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_vertex_type.py", line 102, in from_dict
    "properties": [CreatePropertyMeta.from_dict(_item) for _item in obj["properties"]] if obj.get("properties") is not None else None
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_vertex_type.py", line 102, in <listcomp>
    "properties": [CreatePropertyMeta.from_dict(_item) for _item in obj["properties"]] if obj.get("properties") is not None else None
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/create_property_meta.py", line 90, in from_dict
    "property_type": GSDataType.from_dict(obj["property_type"]) if obj.get("property_type") is not None else None
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/gs_data_type.py", line 90, in from_dict
    return cls.from_json(json.dumps(obj))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gs_interactive/models/gs_data_type.py", line 123, in from_json
    raise ValueError("No match found when deserializing the JSON string into GSDataType with oneOf schemas: PrimitiveType, StringType, TemporalType. Details: " + ", ".join(error_messages))
ValueError: No match found when deserializing the JSON string into GSDataType with oneOf schemas: PrimitiveType, StringType, TemporalType. Details: 1 validation error for PrimitiveType
primitive_type
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.6/v/string_type, Multiple matches found when deserializing the JSON string into StringTypeString with oneOf schemas: FixedChar, LongText, VarChar. Details: 1 validation error for FixedChar
char
  Input should be a valid dictionary or instance of FixedCharChar [type=model_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.6/v/model_type, 1 validation error for TemporalType
temporal
  Input should be a valid dictionary or instance of TemporalTypeTemporal [type=model_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.6/v/model_type

It seems that the json string can be deserialized into LongText and VarChar. Which is not expected by us.

zhanglei1949 commented 3 months ago

Maybe it is related to the LongText's nullable definition

    LongText:
      x-body-name: long_text
      type: object
      required:
        - long_text
      properties:
        long_text:
          type: string
          nullable: true
zhanglei1949 commented 1 month ago

Fixed via https://github.com/alibaba/GraphScope/pull/4091