Skip to content

Fix feature_value position backfill during 9.0.0 upgrade - #1818

Merged
Quetzacoalt91 merged 1 commit into
PrestaShop:7.6.xfrom
Codencode:fix-41554-fix/ps900-feature-value-position-backfill
Jun 2, 2026
Merged

Fix feature_value position backfill during 9.0.0 upgrade#1818
Quetzacoalt91 merged 1 commit into
PrestaShop:7.6.xfrom
Codencode:fix-41554-fix/ps900-feature-value-position-backfill

Conversation

@Codencode

@Codencode Codencode commented May 27, 2026

Copy link
Copy Markdown
Member
Questions Answers
Description? This PR fixes the PrestaShop 9.0.0 upgrade path for shops that already have feature values.

When the new position column is added to feature_value, existing rows all receive the default value 0, which can cause ordering issues. This change adds a dedicated upgrade step that initializes sequential positions per feature during the 9.0.0 migration, while avoiding overwriting already-initialized data.
BC breaks? yes
Deprecations? yes
Fixed ticket? Fixes PrestaShop/PrestaShop#41554
Sponsor company Codencode snc
How to test? 1. Install PS version 8.x.x
2. Upgrade to PrestaShop 9.x.x
3. Check that the position field in the feature_value table is correctly populated and try changing the position of the values in the admin panel.

NOTE

The positions could also have been set using this query:

UPDATE ps_feature_value fv
INNER JOIN (
    SELECT
        id_feature_value,
        ROW_NUMBER() OVER (
            PARTITION BY id_feature
            ORDER BY id_feature_value ASC
        ) - 1 AS new_position
    FROM ps_feature_value
) x ON x.id_feature_value = fv.id_feature_value
SET fv.position = x.new_position;

However, I preferred to create a PHP file for compatibility reasons with different MySQL / MariaDB versions.

@Codencode Codencode added this to the 7.6.6 milestone May 27, 2026
@Codencode
Codencode requested a review from Quetzacoalt91 May 27, 2026 06:40
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard May 27, 2026
@Codencode
Codencode requested review from a team and kpodemski May 27, 2026 06:45
Comment on lines +22 to +24
if (empty(DbWrapper::executeS('SHOW TABLES LIKE "' . _DB_PREFIX_ . 'feature_value"'))) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems not relevant to check for existence of this table, what do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, I'll correct it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpodemski
I removed the checks on both the table and the field because we are sure they exist.

Comment thread upgrade/php/ps_900_init_feature_value_positions.php
@Codencode

Codencode commented May 27, 2026

Copy link
Copy Markdown
Member Author

@Quetzacoalt91 @kpodemski
Some files have the header/license in the old format, for example:
https://github.com/PrestaShop/autoupgrade/blob/dev/tests/integration/MarketplaceAndModuleCompatibilityTest.php

Should I fix them in this PR?

Also, I’m not sure whether targeting the dev branch was the right choice. Maybe I should have targeted the 7.6.x branch?

Also, there are errors (example: https://github.com/PrestaShop/autoupgrade/actions/runs/26496496929/job/78025905639?pr=1818) that do not depend on my change, perhaps precisely because I need to change branch?

@Quetzacoalt91

Copy link
Copy Markdown
Member

Yes, can you please target the 7.6.x branch so your change can reach faster a stable release?

I've seen your how-to-test field, and can you tell me if that's solving an issue while using the shop?

@Codencode
Codencode force-pushed the fix-41554-fix/ps900-feature-value-position-backfill branch from 340cf4b to 17a106e Compare May 27, 2026 14:01
@Codencode
Codencode changed the base branch from dev to 7.6.x May 27, 2026 14:02
@Codencode
Codencode force-pushed the fix-41554-fix/ps900-feature-value-position-backfill branch from 17a106e to 22e4523 Compare May 27, 2026 14:09
@Codencode

Copy link
Copy Markdown
Member Author

Yes, can you please target the 7.6.x branch so your change can reach faster a stable release?

@Quetzacoalt91, I performed the rebase, but I ran into some difficulties, so I had to do a reset and re-add the changes. That's why there's now only one commit, unlike before when there were two, but the final result is the same (the first commit, which was modified by the second, is missing).

I've seen your how-to-test field, and can you tell me if that's solving an issue while using the shop?

Yes, you can see the issue that explains in detail the problem visible in the admin: PrestaShop/PrestaShop#41554

@Quetzacoalt91

Copy link
Copy Markdown
Member

I've the updated the base branch so the CI does not fail for a missing library canvas. Can you please rebase?

@Codencode
Codencode force-pushed the fix-41554-fix/ps900-feature-value-position-backfill branch from 22e4523 to be07de0 Compare June 1, 2026 14:27
@Codencode

Copy link
Copy Markdown
Member Author

@Quetzacoalt91 done

@sonarqubecloud

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

@ps-jarvis ps-jarvis added the Waiting for QA Status: Action required, Waiting for test feedback label Jun 1, 2026
@ps-jarvis ps-jarvis moved this from Ready for review to To be tested in PR Dashboard Jun 1, 2026
@ingridusta ingridusta self-assigned this Jun 2, 2026

@ingridusta ingridusta left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Codencode,

Thanks for the catch !

I reproduced the bug :

Image Image


And with ur fix :

Image Image

Thanks ! It's QA approved ✅

@ingridusta ingridusta added QA ✔️ Status: Check done, Code approved and removed Waiting for QA Status: Action required, Waiting for test feedback labels Jun 2, 2026
@Quetzacoalt91
Quetzacoalt91 merged commit 67c051c into PrestaShop:7.6.x Jun 2, 2026
78 of 80 checks passed
@github-project-automation github-project-automation Bot moved this from To be tested to Merged in PR Dashboard Jun 2, 2026
@ps-jarvis ps-jarvis moved this from Merged to To be tested in PR Dashboard Jun 2, 2026
@Codencode
Codencode deleted the fix-41554-fix/ps900-feature-value-position-backfill branch June 2, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Migration script QA ✔️ Status: Check done, Code approved

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

BIG BUG when upgrading to PrestaShop 9.x from previous versions, related to feature value positions.

6 participants