Azure / Azure/azure-functions-durable-python
Serialization/Deserialization doesn't handle Generics and generates Non-deterministic workflow error
- Vorherrschende Sprache
- Python
- Sterne
- 157
- Forks
- 70
- Ø Merge
- 2 T. 10 Std.
- Gemergte PRs (30 T.)
- 2
Beschreibung
🐛 **Describe the bug**
When a Pydantic Generic object is returned in an activity function `azure.functions._durable_functions._serialize_custom_object` returns "__class__": "ClassName[GenericSpecificClass]". When `azure.functions._durable_functions._deserialize_custom_object` is called in the calling orchestrator, getattr(module, "ClassName[GenericSpecificClass]") fails: ClassName exists but not the specialized "ClassName[GenericSpecificClass]".
🤔 **Expected behavior**
Serialization and deserialization handles Generics.
**Current behaviour**
Deserialization fails with `AttributeError: module 'xxx.xxx' has not attribute 'ClassName[GenericSpecificClass]'`and produces a Non-Deterministic Workflow error
☕ **Steps to reproduce**
```python
from pydantic import BaseModel
from typing import Generic
import azure.functions as func
import azure.durable_functions as df
class A(BaseModel, Generic[T]):
a: T
def to_json():
return self.model_dump(mode="json")
@classmethod
def from_json(cls, data: dict):
return cls(**data)
myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@myApp.orchestration_trigger(context_name="context")
def orchestrator_function(context: df.DurableOrchestrationContext):
x = yield context.call_activity("hello", None)
@myApp.activity_trigger(input_name="params")
def hello(params):
return A[str](a="xxx")
```
Beitragsleitfaden
Rechercherichtung
Beginne damit, azure.functions._durable_functions._serialize_custom_object und _deserialize_custom_object anhand des Pydantic Generic-Beispiels im Issue nachzuverfolgen. Reproduziere den Ablauf von der Activity zum Orchestrator und untersuche, wie der Name der generischen Klasse serialisiert und nachgeschlagen wird. Als abgeschlossen gilt die Aufgabe, wenn das Beispiel erfolgreich deserialisiert wird, ohne AttributeError oder einen nichtdeterministischen Workflow-Fehler.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100