Skip to content

🍻 [Bug] Ordered a beer, tab increased, but my glass is still empty (and the beer was out of stock!) #1

@thomasmaerz

Description

@thomasmaerz

Environment

  • OS: Barstool v2.0
  • Time Elapsed: 3 hours
  • Thirst Level: Critical

Steps to Reproduce

  1. Walk into the Virtual Bar.
  2. Send a POST request to /orders/ containing an order_item for a drink that is technically marked as in_stock: false.
  3. Wait indefinitely for the bartender to pour the drink.
  4. Check your tab by fetching your Patron record.

Expected Behavior

The bartender should politely inform me that the keg is tapped out (e.g., return a 400 Bad Request or an in_stock error message) so I can order something else.

Actual Behavior

The bartender takes my order in silence, stares blankly into the void, never pours the drink, AND charges my tab! My balance increased, but my physical glass is tragically empty. I've been sitting here for three hours. Please help.


🕵️‍♂️ Technical Root Cause

Jokes aside, I took a look at the source code while waiting for my drink, and I found the actual issue. In bartender/serializers.py, the OrderSerializer's create() and update() methods do not validate whether the requested drinks are actually in stock.

    def create(self, validated_data):
        order_items = validated_data.pop('order_items', [])
        order = Order.objects.create(**validated_data)

        for order_item in order_items:
            # BUG: No check here if order_item['drink'].in_stock is True! 
            # The bartender happily takes orders and charges for out-of-stock items.
            OrderItem.objects.create(order=order, **order_item)

        return order

Proposed Fix:
Add a validation step in OrderSerializer.validate() to check if all requested drink items have in_stock == True. If not, raise a serializers.ValidationError("We are out of stock!").

I'd submit a PR, but I'm too parched. 🍻

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions