setter and getter can not work in sqlmodel , but it works in sqlalchenmy #557
Replies: 1 comment
-
Works well in current version (0.0.24): from typing import Optional
from sqlalchemy.orm import declarative_base
from sqlmodel import Field, SQLModel
SqlalchemyBase = declarative_base()
def fakehash(data):
return "fake" + str(data)
class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
hashed_password: str
@property
def password(self):
return self.hashed_password
@password.setter
def password(self, value):
self.hashed_password = fakehash(value) # "fake"+value
class Config:
arbitrary_types_allowed = True
user = User()
user.password = "123"
print(user.hashed_password)
print(user.password) Output:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
for auto conservate password from plain string to hashed str, in Sqlalchemy model , it is very common to use setter and getter .
It works in sqlalchemy. but it can not work in sqlmodel.
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.0
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions