Implementation of `has` macro is incomplete
还没有人认领这个 Issue。
评估
调研方向
从 src/celpy/evaluation.py 第 1273 行附近的 has 实现开始,然后追踪 MessageType 如何表示被省略的 protobuf 字段和具有默认值的 protobuf 字段。在选择方案之前,先用一个最小的 protobuf 示例复现报告中的行为;当 has 遵循文档化的 proto2 和 proto3 presence 规则,且不会将默认值与已设置的字段混淆时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
The has macro is implemented by visiting the child nodes and returning true if there was not a CELEvalError. However, this makes it impossible for Protobuf messages to be handled properly.
The docstring describes the algorithm:
If e evaluates to a protocol buffers version 2 message and f is a defined field:
If f is a repeated field or map field, has(e.f) indicates whether the field is non-empty.
If f is a singular or oneof field, has(e.f) indicates whether the field is set.
If e evaluates to a protocol buffers version 3 message and f is a defined field:
If f is a repeated field or map field, has(e.f) indicates whether the field is non-empty.
If f is a oneof or singular message field, has(e.f) indicates whether the field is set.
If f is some other singular field, has(e.f) indicates whether the field's value is its default value (zero for numeric fields, false for booleans, empty for strings and bytes).
However, as far as I can tell, this is impossible to implement correctly no matter what. If you have a MessageType populated by omitting fields that are not present, you get incorrect behavior since unset fields are null instead of their default values. If you have a MessageType populated by setting default values, you get incorrect behavior because has returns true for fields that it shouldn't. What is needed is for has to return false while still populating the default value.
I don't currently have a minimal reproduction, in part because the library I am currently working on does not actually use the cel-python MessageType, but instead uses its own (though I did try to use cel-python MessageType and ran into basically the same issue, so I am pretty sure, as long as I am not missing anything, that it is similarly applicable.) That said, I hope this explanation is enough to either point me in the right direction: it seems like I am either misunderstanding how to use cel-python, or it is simply missing support for this. I think that there needs to be a way for has to be specialized for a given type; idiomatically it'd be best, in my opinion, if has could somehow call __contains__; then Python types, including MessageType, could just implement __contains__ and __getitem__ to do the right thing.
I would be willing to try to submit a PR to rectify this in the future if this sounds like a real issue and my solution would be OK, but I don't currently have a good enough understanding of how lark-parser works, so it may not be something I have time to approach for the moment.
- 主要语言
- Python
- 星标
- 174
- 派生
- 41
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloud-custodian/cel-python 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
cloud-custodian/cel-python#180 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 68/100
cloud-custodian/cel-python#194 ·
-
documentation enhancement tracking
难度 3/5 1-2 天 新手友好度 68/100
cloud-custodian/cel-python#182 ·
-
Refresh Features可能重新可做 @slott56 于 138 天前认领,目前没有进行中的 PR。 未关闭dependencies
cloud-custodian/cel-python#172 · 2 条评论 · 已指派 1 人 ·
-
Permit multiple threads to share a common Environment可能重新可做 @Quantum0uasar 于 126 天前认领,目前没有进行中的 PR。 未关闭enhancement
cloud-custodian/cel-python#169 · 3 条评论 · 已指派 1 人 ·
查看 cloud-custodian/cel-python 的全部 Issue
相似的 Issue
-
needs triage
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")可能已有人在做 @mayureshsonawane17 今天认领。 未关闭Waiting for: Product Owner
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
ayghri/i-have-adhd#249 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
modelscope/FunASR#3762 ·
维护者通常 1 天内回复