You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This does not work in beanie, however, as beanie seems to ignore private attributes (_humanity) when writing to the database. "All right", I thought, "I'll just change the name."
However, if I do that (say, _humanity -> raw_humanity), then print(character.humanity) works, but character.humanity = 5 raises a ValueError from pydantic stating that Character objects have no field "humanity".
I could fix this by changing the name of the @property, but that would require lots of code changes elsewhere. I'd like to avoid that if possible.
I also found an approach using @root_validator, but that has its own pitfalls and issues.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm migrating to beanie from a different ODM. Here's an extremely simplified view of one of my models:
This does not work in beanie, however, as beanie seems to ignore private attributes (
_humanity
) when writing to the database. "All right", I thought, "I'll just change the name."However, if I do that (say,
_humanity
->raw_humanity
), thenprint(character.humanity)
works, butcharacter.humanity = 5
raises a ValueError from pydantic stating thatCharacter
objects have no field "humanity".I could fix this by changing the name of the
@property
, but that would require lots of code changes elsewhere. I'd like to avoid that if possible.I also found an approach using
@root_validator
, but that has its own pitfalls and issues.What is my best approach here?
Beta Was this translation helpful? Give feedback.
All reactions