Polymorphic fields
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 12/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- python
调研方向
The issue centres on the polymorphic_fields=True option of Faust's Record class and the _blessed_key attribute, plus the from_data override in the reporter's snippet; the payload names no specific files. Decide first whether a custom blessed key format is meant to be supported, since the issue asks that question rather than requesting a specific change. Done would mean a maintainer records that decision, with either a documented extension point or a closed issue.
由索引模型根据 Issue 内容生成。
描述
I am in the process of converting a legacy system that was using an in-house streaming package to Faust. We had our own "polymorphic typing" implementation that made messages look like this:
{
"class": "MessageClassType",
"data": {"id": "1234", "other_field": "4321", ...}
}
I've been trying to match this to Faust's Polymorphic fields, but I'm stuck. From the documentation, I cannot understand if this feature should be used only when Faust has produced messages and added the blessed key, or if I can customize this. I am currently not yet producing messages using Faust, so it's unclear if Faust will always add the blessed key to the messages.
So far, I was able to come up with something like this:
class MyMessage(Record, polymorphic_fields=True, serializer='avroschema'):
_blessed_key = 'blessed_key'
class_: str
@classmethod
def from_data(cls, data: Mapping, **kwargs):
if 'class' in data:
data = {**data, "class_": data['class'], 'blessed_key': {"ns": data['class']}}
return super().from_data(data, **kwargs)
class PolymorphicMessageField(Record):
id: str
other_field: str
class MyMessagePolymorphic(MyMessage, namespace='MyMessagePolymorphic'):
class_ = "MyMessagePolymorphic"
data: PolymorphicMessageField
This seems to be working. If I receive a message with the contents {"class": "MyMessagePolymorphic", "data": {"id": "1234", "other_field": "4321"}}, I am able to check the type on both the message (matching MyMessagePolymorphic), and the data field (matching PolymorphicMessageField).
However, this seems overly clunky for a couple reasons:
- I am specifying the blessed key by overriding the underscore attribute
_blessed_key. - I need to set the namespace to the same class name which causes repetition, otherwise Faust automatically appends the module name into it.
- It is necessarily the case that the blessed key will be a dictionary with the class name inside a
nsfield, so I also need to override thefrom_datamethod.
Is there a better or more supported way to accomplish this?
- 主要语言
- Python
- 星标
- 1.9k
- 派生
- 205
- 平均合并
- 2 小时 2 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
faust-streaming/faust 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 86/100
faust-streaming/faust#804 ·
-
scripts/install script forces use of ./venv virtualenv, impossible to use with virtualenvwrapper未关闭
难度 1/5 1 小时以内 新手友好度 62/100
faust-streaming/faust#28 · 1 条评论 ·
-
[BUG] SASL PLAINTEXT producer initialization fails : missing sasl_plain_username/password可能已有人在做 @wbarnha 于 56 天前认领。 未关闭
faust-streaming/faust#794 · 2 条评论 · 1 个 reaction · 已指派 2 人 ·
-
难度 4/5 3-5 天 新手友好度 18/100
faust-streaming/faust#670 ·
-
难度 4/5 3-5 天 新手友好度 18/100
faust-streaming/faust#666 ·
查看 faust-streaming/faust 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
OpenFreeEnergy/openfe#2371 ·
维护者通常 2 天内回复
-
HMDB's smiles file writes "None" for metabolites with an empty <smiles/> (file not currently used)未关闭
难度 2/5 1-3 小时 新手友好度 80/100
NCATSTranslator/Babel#1269 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 80/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 64/100
bcgov/nr-hydrometric-rating-curve#443 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100