Python-使用SQLModel中的过渡状态机
我想在我的SQLModel模式中使用状态计算机,但我会遇到类型错误。
class Invoice(BaseSQLModel, table=True):
id: Optional[int] = Field(primary_key=True)
def __init__(self):
super().__init__()
default_status = fsm.initial_payment_state
self.fsm = fsm.get_payment_fsm(default_status). # Throws an error here because fsm is not an attribute of the class
是否可以声明创建列时忽略的属性?如何在此处声明FSM和状态属性?
我已经尝试过,但是当试图调用fsm.add_model(self)
时,代码被卡住了
class Invoice(BaseSQLModel, table=True):
id: Optional[int] = Field(primary_key=True)
_fsm: "Machine" = PrivateAttr()
def __init__(self):
super().__init__()
default_status = fsm.initial_payment_state
self._fsm = fsm.get_payment_fsm(default_status)
self._fsm.add_model(self). # Gets stuck here
# Allowing me to declare additional attributes
class Config:
extra = Extra.allow
arbitrary_types_allowed = True
I want to use a state machine in my SQLModel schema but I'm getting type errors.
class Invoice(BaseSQLModel, table=True):
id: Optional[int] = Field(primary_key=True)
def __init__(self):
super().__init__()
default_status = fsm.initial_payment_state
self.fsm = fsm.get_payment_fsm(default_status). # Throws an error here because fsm is not an attribute of the class
Is it possible to declare an attribute which is ignored when creating columns? How can I declare the fsm and state attributes here?
I've tried this but then the code gets stuck when trying to call fsm.add_model(self)
class Invoice(BaseSQLModel, table=True):
id: Optional[int] = Field(primary_key=True)
_fsm: "Machine" = PrivateAttr()
def __init__(self):
super().__init__()
default_status = fsm.initial_payment_state
self._fsm = fsm.get_payment_fsm(default_status)
self._fsm.add_model(self). # Gets stuck here
# Allowing me to declare additional attributes
class Config:
extra = Extra.allow
arbitrary_types_allowed = True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论