Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PR #49504 breaks database save when using certain numeric values with string fields. #49701

@apreiml

Description

@apreiml

Laravel Version

10.40.0

PHP Version

8.2

Database Driver & Version

No response

Description

#49504 breaks saving of string columns in certain cases.

As shown in the reproduction steps, sometimes string fields contain numbers that should not be parsed as decimals. I'd like to suggest to revert the pull request. I guess the dirty state issue in that pr could be solved using casts or mutators.

Steps To Reproduce

To trigger the bug store an integer in a string field of a model and use an invalid integer on the next save. E.g.

$address = new Address(['building' => '107']); // building is a varchar(255)
$address->save();

$address->building = '5 '; // note the whitespace 
$address->save();

will result in:

1) Tests\Import\Stories\AddressTest::testStrangeBuilding
Brick\Math\Exception\NumberFormatException: The given value "5 " does not represent a valid number.

/home/ape/s/ws/wasser_web/vendor/brick/math/src/BigNumber.php:69
/home/ape/s/ws/wasser_web/vendor/brick/math/src/BigNumber.php:76
/home/ape/s/ws/wasser_web/vendor/brick/math/src/BigDecimal.php:56
/home/ape/s/ws/wasser_web/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:2104

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions