This is a minor style nit, but since you don't use `flagged` again I'd probably just fold it into the call to update: `session.update(..., flagged=check_flagged(codename), ...)`. Up to you if you want to make this change or not.