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,115
  • 3
  • 36
  • 75
Daniel Fortunov
  • 41,122
  • 25
  • 79
  • 104

0 Answers0