kcl-lang / lib

KCL Multiple Language Bindings including Rust, Go, Python, Java, Kotlin, .NET, Swift, Lua, Node.js, Zig, C, C++, WASM, etc.
https://www.kcl-lang.io/docs/reference/xlang-api/overview
Apache License 2.0
8 stars 10 forks source link

Inconsistent protobuf versions kclvm->python client #158

Open diefans opened 3 hours ago

diefans commented 3 hours ago

Bug Report

I stumbled upon an inconsistency of protobuf versions used and also pinned/validated:

In the python client protobuf is pinned to >=4.25.3 (https://github.com/kcl-lang/lib/blob/main/python/pyproject.toml#L18) The python client protobuf itself validates against 5.27.0 (https://github.com/kcl-lang/lib/blob/main/python/kcl_lib/api/spec_pb2.py#L14)

And the most relevant part is, that the kclvm/api implements also a different version. If you take the example Python client example you receive class references, which are not implemented in protobuf >= 5.27.0:

import kcl_lib.api as api

exec_args = api.ExecProgram_Args(k_filename_list=["api/tests/schema.k"])
args = api.GetSchemaTypeMapping_Args(exec_args=exec_args)
api = api.API()
result = api.get_schema_type_mapping(args)

assert result.schema_type_mapping.__module__ == "google._upb._message"
assert result.schema_type_mapping.__class__.__name__ == "MessageMapContainer"

If you try to import that class directly from protobuf you get an import error:

from google._upb._message import MessageMapContainer
*** ImportError: cannot import name 'MessageMapContainer' from 'google._upb._message' (/home/olli/code/bm/integration-config/.devenv/state/venv/lib/python3.12/site-packages/google/_upb/_message.abi3.so)

There is an open issue https://github.com/protocolbuffers/protobuf/issues/16935#issuecomment-2135603608 which describes this.

kcl-lib == 0.10.3

Peefy commented 3 hours ago

Thanks for the feedback. Maybe we need to change the protobuf deps to >=5.27.0 👀