O'Reilly logo
  • Ivan Ivanov thinks this is interesting:

s = s.where(line_items.c.order_id == order_id)


Cover of Essential SQLAlchemy, 2nd Edition


it's better to add the following line, after this line:
s = s.order_by(line_items.c.cookie_id.desc())
in this way we can be sure that firstly function decrease number of 'dark chocolate chip' and only then throw an exception on 'chocolate chip'