{{ message }}
Repository navigation
Preserve the scalar type of an extra property default value in the CQRS layer - #42343
Closed
ousamabenyounes wants to merge 1 commit into
Closed
ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
|
Hello @ousamabenyounes! This is your first pull request on PrestaShop repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
…RS layer ExtraPropertyDefinition types its $defaultValue as int|float|string|bool|null so a value read back from an INT/BOOL/FLOAT column keeps its declared type. The add command and the edit query-result DTO narrowed it to ?string, forcing a lossy (string) cast and rejecting non-string scalars passed through the CQRS layer (e.g. an integer default coming from the Admin API JSON payload, which raised a TypeError under strict_types). Widen AddExtraPropertyDefinitionCommand and EditableExtraPropertyDefinition to the same scalar union, drop the (string) cast in the editing query handler, and move that cast to the form data provider where the TextType field needs a string for display. Back-office form rendering is therefore unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ousamabenyounes
force-pushed
the
fix/issue-41829
branch
from
August 16, 2026 16:52
0d84d8b to
a3c5e13
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
ExtraPropertyDefinitiontypes its$defaultValueasint|float|string|bool|null(docblock@param scalar|null), and the repository already casts the raw DB string back to that declared type viaExtraPropertyValueCaster::castFromDb(). But the CQRS layer narrowed the same value to?string:AddExtraPropertyDefinitionCommand::$defaultValuewas?string, so a non-string scalar passed programmatically (e.g. an integer default coming from the Admin API JSON payload) raised aTypeErrorunderdeclare(strict_types=1).EditableExtraPropertyDefinition::$defaultValuewas?string, andGetExtraPropertyDefinitionForEditingHandlerforced a(string)cast when building it — losing the scalar type carried by the entity.This PR aligns the CQRS layer with the entity:
$defaultValue(constructor param + getter) toint|float|string|bool|nullinAddExtraPropertyDefinitionCommandandEditableExtraPropertyDefinition.(string)cast inGetExtraPropertyDefinitionForEditingHandlerso the edit DTO carries the real scalar.(string)cast toExtraPropertyDefinitionFormDataProvider, where the back-officeTextTypefield needs a string for display. The rendered form value is therefore unchanged — the cast simply happens at the form boundary instead of inside the query handler.No BC break: string defaults continue to work everywhere (string is part of the widened union), and the only in-repo command caller (the BO form data handler) still passes a string.
How to test
Unit tests cover the type-preservation contract on both CQRS classes:
Each test constructs the class with
int,float,bool,stringandnulldefaults and asserts (assertSame) that the getter returns the same typed value.Test verification (RED → GREEN)
RED — new tests on
develop(before the production change): theint/float/booldata sets fail because the constructor still declares?string:GREEN — after widening the types (full ExtraProperty unit suites, includes the 12 new cases):
php-cs-fixer(dry-run) andphpstanon the changed files both report no errors.