#41161·magento2

Target rule is throwing Undefined array key while indexing

Author: adarshkhatriCreated Aug 28, 2026Updated Sep 28, 2026
LabelsIssue: needs updateReported on 2.4.7 -p10

Preconditions and environment

Steps to reproduce

  • Create 2 upsell/related rules:
  1. Rule A: a. Matching product: category- Category A b. Displaying product: category- Category B

  2. Rule B: a. Matching product: category- Category P b. Displaying product: category- Category Q

  • Create 2 products:
  1. Product "My Product". Assign to Category A.
  2. Product "Your Product". Assign to Category P.
  • After all the indexer changelogs have finished, do a GQL query to get the related/upsell products for My product. You should get the upsell/related products from "Category B".
  • Tail your server logs.
  • Edit product My product and change its category to Category P.
  • Let the indexer changelog kick in.
  • Observe the error in the logs.

You should see an error like this:

Cron Job indexer_update_all_views has an error: Warning: Undefined array key 171 in /vendor/magento/module-target-rule/Model/Indexer/TargetRule/AbstractAction.php on line 180. Statistics: {"sum":0,"count":1,"realmem":0,"emalloc":0,"realmem_start":140509184,"emalloc_start":65836080} [] []

The culprit line is:

$entitiesToDelete[$ruleId] = $existingEntities[$ruleId];

Expected result

  1. It should complete the indexer and should not throw an error.
  2. The upsell/related product request for my product should give you upsell/related products from Category Q only.
  3. The DB table should have only one row for this product for Rule B.

Actual result

  1. It throws an error.
  2. The upsell/related product request for my product gives you results from both Category P and Category Q.

Additional information

While indexing, it assigns the product to a new rule, but it fails to remove old entries from the DB table, which is why we have entries for both rules.

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”.