Skip to content

Fix Product Links always being processed in afterSave#40746

Open
OddScenario wants to merge 1 commit intomagento:2.4-developfrom
OddScenario:feature/stop-product-links-post-processing
Open

Fix Product Links always being processed in afterSave#40746
OddScenario wants to merge 1 commit intomagento:2.4-developfrom
OddScenario:feature/stop-product-links-post-processing

Conversation

@OddScenario
Copy link
Copy Markdown

@OddScenario OddScenario commented Apr 17, 2026

Description (*)

Magento\Catalog\Model\Product::afterSave() unconditionally called getLinkInstance()->saveProductRelations($this) on every save, re-processing product links even when the caller explicitly indicated that links should be left untouched. Magento\Catalog\Model\ProductRepository already exposes an ignore_links_flag to opt out of link pre-processing, but afterSave() never checked that flag — so the unchanged product_links were still re-processed and written to the database on every save.

This becomes visible under concurrent saves against the same product (e.g. updating multiple storeviews in parallel). The post-processing races with itself and fails with:

HTTP 400 — "The linked products data is invalid. Verify the data and try again."

even when the PUT body contains no product_links at all.

This PR makes afterSave() respect ignore_links_flag, and updates ProductRepository::processLinks() to set the ignore_links_flag when the links are null.

Manual testing scenarios (*)

Preconditions: a Magento instance with ≥2 storeviews and at least 1 product that has related / upsell / crosssell links configured (e.g. 24-MB01 from sample data).

  1. Run the script below against the instance.
  2. Before this fix: at least one response returns HTTP 400 with "The linked products data is invalid. Verify the data and try again.", even though no product_links are in any PUT body.
  3. After this fix: product_links are only processed when present in the PUT body.
  const BASE_URL = 'https://magento.test';
  const TOKEN    = '<admin-or-integration-token>';
  const SKU      = '24-MB01';
  const STORE_CODES = ['all', 'store_1', 'store_2', 'store_3', 'store_4', 'store_5', 'store_6', 'store_7', `store_8`];

  const randomName = () =>
    `perf-test-${Math.random().toString(36).slice(2, 10)}`;

  const putForStore = (store) =>
    fetch(`${BASE_URL}/rest/${store}/V1/products/${encodeURIComponent(SKU)}`, {
      method: 'PUT',
      headers: {
        Authorization: `Bearer ${TOKEN}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ product: { name: randomName() } }),
    }).then(async (res) => ({
      store,
      status: res.status,
      body: await res.text(),
    }));

  const results = await Promise.all(STORE_CODES.map(putForStore));

  for (const { store, status, body } of results) {
    console.log(`[${store}] ${status} ${body.slice(0, 200)}`);
  }

  const failed = results.filter((r) => r.status >= 400);
  process.exit(failed.length ? 1 : 0);

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented Apr 17, 2026

Hi @OddScenario. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@ct-prd-pr-scan
Copy link
Copy Markdown

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

@OddScenario
Copy link
Copy Markdown
Author

@magento run all tests

@OddScenario OddScenario changed the title FIx Product Links always being processed in afterSave Fix Product Links always being processed in afterSave Apr 17, 2026
@ct-prd-pr-scan
Copy link
Copy Markdown

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

3 similar comments
@ct-prd-pr-scan
Copy link
Copy Markdown

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

@ct-prd-pr-scan
Copy link
Copy Markdown

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

@ct-prd-pr-scan
Copy link
Copy Markdown

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

@OddScenario OddScenario marked this pull request as ready for review April 17, 2026 12:06
@engcom-Dash engcom-Dash added the Priority: P3 May be fixed according to the position in the backlog. label Apr 21, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

2 participants