AllenNeuralDynamics / AllenNeuralDynamics/one-liner

Pickle errors with pydantic

Aperta
#62 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
3
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When returning ``model_dump()`` from a pydantic model, if its in python mode (default behavior) it will preserve python objects which breaks the client side code.

# Example (with Enum)

## RouterServer

```python
class Nums(Enum):
ONE = "one"
TWO = "two"

class Model(BaseModel):
input: str
num: Nums

class Test:
def test(self, input: str, num: Nums = []) -> Model:
# model_dump runs in python mode and will preserve the Nums object
# ex. {'input': 'Hello'. 'num': '}
return Model(input=input, num=num) .model_dump()
```
## RouterClient

```python
client = RouterClient()
print(client.call_by_name("test", args=["Hello World!", "one"]))
```

I believe one-liner will pickle the return as ``'input': 'Hello'. 'num': '}``

Then the client will try to do: ``__main__.Nums.ONE`` and fail. I think this will be true for any python object from ``model_dumps(mode=python)``

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.