Polymorphic fields
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 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分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 · 担当者 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時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[Maintainer] task area:visualizer
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
RailtownAI/railtracks#1824 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
apache/datafusion#27688 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
mloda-ai/mloda-registry#1664 ·
メンテナーはふだん 1 日以内に返信