by SmellTheGlove · 2y ago · 0 comments
For something like this where you’re generating a unique id and probably need it in every model, it’s better to write a new Base model that includes things like your unique id, created/changed at timestamps, etc. and then subclass it for every model. Basically, write your model boilerplate once and inherit it. This way you can only fuck this up once and you’re bound to catch it early before you make this mistake in a later addition like subscription management.
The time people spend learning the quirks of an ORM is much better put into learning SQL.
The intent is to pass a callable, not to call a function and populate an argument with what it returns.
This mistake would have happened even if they did not use ChatGPT.
Some linters like pyright can identify dangerous defaults in function call, like `def hello(x=[]): pass` (mutable values shouldn't be a default). Linter plugins for widely-used and critical libraries like SQLAlchemy are nice to have.