breakpoint() drops you into the debugger where the bug is
It's one builtin call with no import, and PYTHONBREAKPOINT=0 turns every one of them off in production.
def apply_discount(order):
breakpoint()
...From there you can inspect locals, step through, and evaluate expressions against the live state. If ipdb is installed, set PYTHONBREAKPOINT=ipdb.set_trace for a nicer debugger.
pythondebugging