reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
18.84k stars 1.07k forks source link

The by_alias=True parameter for the dict() and model_dump() functions is not selecting the alias in a class derived from rx.Model correctly. #3391

Open aden-collector opened 3 months ago

aden-collector commented 3 months ago

Discussed in https://github.com/orgs/reflex-dev/discussions/3358

Originally posted by **aden-collector** May 21, 2024 We are using reflex version 0.5.0post1. Our code used the dict() function with by_alias=True to get a dictionary from an object of a data class. The data class inherited from rx.Base and has a few field names. This is a sample field definition: name: str = Field(alias="Name"). Function dict() worked in the past but stopped working recently. The key value in the resulting dictionary was "name" instead of the alias "Name". We heard that function dict() was deprecated so we tried using the model_dump() function with the parameter by_alias=True. We changed the data class to inherit from rx.Model instead of rx.Base. The dictionary returned by model_dump() doesn't use the alias. We have the same issue as using the dict() function (key name "name" in the dictionary instead of the alias "Name")
aden-collector commented 2 months ago

Is there any update regarding solving this issue?