Closed mcvady closed 8 months ago
Hello @mcvady,
transitions
decorates models with trigger and state check methods as well as a generic trigger
method to process events by name. I am not super familiar with pydantic but it seems like BaseModel does not allow to set attributes that haven't been explicitly defined. One way to deal with this is to allow extra attributes during model initialisation:
from pydantic import BaseModel, ConfigDict
from transitions import Machine
class Matter(BaseModel):
model_config = ConfigDict(extra='allow')
name: str
lump = Matter(name="Mr. Lumpy")
machine = Machine(model=lump)
Maybe there are ways in pedantic to define dynamically added attributes. Maybe it's even possible to define a model and pass it -- like for instance DocMachine -- to transitions for machine configuration. Currently, I would not say that this is a bug but rather the way transitions operates.
Closing this since there has been no feedback for over 2 weeks. Feel free to comment if the issue still persists. I will reopen the issue if necessary.
Thank you for taking the time to report a bug! Your support is essential for the maintenance of this project. Please fill out the following fields to ease bug hunting and resolving this issue as soon as possible:
Describe the bug When trying to use a model based on the Pydantic
BaseModel
class, an exception is raised instantiating the state machine:Minimal working example
Expected behavior The expected behavior was that it were possible to use Pydantic and transitions together.
Additional context