0

Originally asked here but I've narrowed down the problem further.

Python's transitions library's Machine doesn't appear to work with Pydantic BaseModel classes. Even if I allow for arbitrarily adding attributes in the Config subclass, the code gets stuck at the add_model(self) step.

Example:

class TestModel(BaseModel):
    id: Optional[int]
    _fsm: "Machine" = PrivateAttr()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self._fsm = fsm.get_fsm(default_status)
        self._fsm.add_model(self)  # gets stuck here

    class Config:
        extra = Extra.allow
Dave Cook
  • 617
  • 1
  • 5
  • 17
  • Can you explain with more detail what do you mean "the code gets stuck"? – Hernán Alarcón Jul 05 '22 at 00:14
  • When using a debugger, the program doesn't advance past the `add_model` line. It appears to run the line but then everything freezes. – Dave Cook Jul 05 '22 at 12:42
  • I cannot reproduce your error. Using `self._fsm = Machine()` instead of your version seems to run completely without raising any exception. Check [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) to find some recommendations about how to improve your question. – Hernán Alarcón Jul 06 '22 at 03:43
  • Thanks for investigating. It does appear that this does work but there were some serious delays which were causing my execution to stop as I described. It would appear that by adding custom `__str__` and `__repr__` methods to the class, the issue with these delays no longer occurs. – Dave Cook Jul 06 '22 at 12:55

0 Answers0