Skip to content

Product List Customer Segment condition works incorrectly and overloads the website #39615

Open
@zhovnirigor

Description

@zhovnirigor

Preconditions and environment

When there is a customer segment rule with any Product List condition, AND a guest without the quote performs any POST request, the following SQL query is ran in \Magento\CustomerSegment\Model\Segment\Condition\Product\Combine\ListCombine::isSatisfiedBy:
SELECT item.* FROM quote_item item INNER JOIN quote ON item.quote_id = quote.entity_id WHERE ( quote.store_id IN( ? ) ) AND ( quote.is_active = ? )
This is incorrect behavior, and has two undesired consequences:

  1. Segment Rule is applied based on all active quote items for this store, not on guest's quote.
  2. The SQL request above is executed without index keys applied, and for huge quote_item table this creates a significant MaridDB overload for a significant number of POST requests.

This should never happen for the guests that do not have quotes.

  • Magento version 2.4.7-p3

Steps to reproduce

  1. Create a new Customer Segment. Set Apply To to Visitors or Visitors and Registered Customers. In conditions, select a single [Products] Product List condition, and select any subcondition for it (for instance, Attribute Set is Shirts).
  2. In incognito browser window, navigate to the site frontend. Perform any POST request which does not create quote (for instance, submit Contact Us form).

Expected result

Product List condition is processed correctly - if guest doesn't have quote, \Magento\CustomerSegment\Model\Segment\Condition\Product\Combine\ListCombine::isSatisfiedBy returns value based on the operator only (and not getting to the quote items request)

Actual result

The SQL query above is ran. No indexes are used, which overloads MariaDB, and segment is applied based on someone else's quotes.

Additional information

The following patch solves the problem

customer_segments.patch.zip

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: OrderComponent: QuoteIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Reported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions