1

Is there a mixin or other mechanism I can use to cause immediate failure if I assign to unknown column on a model instance?

 new_order = Order()  # Order is a SQLAlchemy model class
 new_order.this_column_does_not_exist = 42  # I want this to raise!

The documentation on Constructors and Object Initialization says

You are free to [...] assign attributes to the instance that are unknown to the ORM

which is in keeping with the conventions of Python, but I'm wondering if there is a way to opt-in to a strict mode of enforcement to avoid latent errors due to typos in column name assignments.

das-g
  • 9,718
  • 4
  • 38
  • 80
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106

0 Answers0