Skip to content

[Bug]: Draft orders query crashes with 500 when a variant has no channel listing (AttributeError: 'NoneType' has no attribute 'price_amount') #6554

Description

@jorgdec

Description of the issue

Querying draftOrders in the Saleor Dashboard returns a 500 error when a draft order contains a line whose product variant is no longer listed in the order's channel. The catalogue-promotion discount logic assumes a variant_channel_listing always exists and
dereferences .price_amount on None, which crashes the entire query and makes the affected draft orders unreachable from the UI.

Steps to reproduce the problem

  1. Create a draft order in channel A that includes a product variant listed in channel A.
  2. Remove the variant's channel listing for channel A (e.g. unpublish it from the channel, or delete the ProductVariantChannelListing).
  3. Open the Draft Orders view in the Saleor Dashboard (which issues the draftOrders query).

What did you expect to happen?

The Dashboard renders the draft orders list. Draft orders containing a line with no current channel listing should be shown gracefully — either with a clear warning/placeholder on the affected line, or with the previously-stored line price — so the user can open
the order, fix it (re-list the variant, remove the line, etc.) without having to drop down to the GraphQL API.

Additional information

The draftOrders query fails with a 500 and the Dashboard view is unusable. Server log:

ERROR saleor.graphql.errors.unhandled: A query failed unexpectedly
Traceback (most recent call last):
File "/app/saleor/graphql/order/types.py", line 2233, in _resolve_total
return calculations.order_total(...)
File "/app/saleor/order/calculations.py", line 931, in order_total
order, _ = fetch_order_prices_if_expired(...)
File "/app/saleor/order/calculations.py", line 89, in fetch_order_prices_if_expired
lines_info = refresh_order_base_prices_and_discounts(...)
File "/app/saleor/order/calculations.py", line 585, in refresh_order_base_prices_and_discounts
refresh_order_line_discount_objects_for_catalogue_promotions(lines_info_to_update)
File "/app/saleor/discount/utils/order.py", line 306, in refresh_order_line_discount_objects_for_catalogue_promotions
discount_data = prepare_order_line_discount_objects_for_catalogue_promotions(...)
File "/app/saleor/discount/utils/order.py", line 343, in prepare_order_line_discount_objects_for_catalogue_promotions
discounted_line = is_discounted_line_by_catalogue_promotion(...)
File "/app/saleor/discount/utils/promotion.py", line 173, in is_discounted_line_by_catalogue_promotion
price_amount = variant_channel_listing.price_amount
AttributeError: 'NoneType' object has no attribute 'price_amount'

Environment

Dashboard version: 3.23.3
Core version: 3.23.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions