diff --git a/barker/barker/routers/voucher/show.py b/barker/barker/routers/voucher/show.py index 8c68eed4..23938448 100644 --- a/barker/barker/routers/voucher/show.py +++ b/barker/barker/routers/voucher/show.py @@ -212,8 +212,19 @@ def from_table( ) ) .unique() - .scalar_one() + .scalar_one_or_none() ) + if item is None: + item = db.execute( + select(Voucher) + .join(Voucher.food_table) + .join(Voucher.customer, isouter=True) + .where(Voucher.id == v) + .options( + contains_eager(Voucher.food_table), + contains_eager(Voucher.customer), + ) + ).scalar_one() if guest is not None: item.customer = guest.customer