Polymorphic fields
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 12/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- stream-processing
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- Python
- Stelle
- 1.9k
- Fork
- 205
- Merge medio
- 2h 2m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di faust-streaming/faust
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
faust-streaming/faust#804 ·
-
scripts/install script forces use of ./venv virtualenv, impossible to use with virtualenvwrapperAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
faust-streaming/faust#28 · 1 commento ·
-
[BUG] SASL PLAINTEXT producer initialization fails : missing sasl_plain_username/passwordForse già presa @wbarnha l’ha presa 56 giorni fa. Aperta
faust-streaming/faust#794 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
faust-streaming/faust#670 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
faust-streaming/faust#666 ·
Tutte le issue di faust-streaming/faust
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[Maintainer] task area:visualizer
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
RailtownAI/railtracks#1824 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
apache/datafusion#27688 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
mloda-ai/mloda-registry#1664 ·
I maintainer di solito rispondono entro 1 giorno