Skip to content

5.x: Possible regression on validation rules #18367

@dereuromark

Description

@dereuromark

Description

I have an app I wanted to upgrade to 5.2
But it then would fail everywhere with

1) App\Test\TestCase\Model\Table\UsersTableTest::testFindAuth
ArgumentCountError: Too few arguments to function Cake\Validation\Validation::notBlank(), 0 passed and exactly 1 expected

/shared/httpd/app/vendor/cakephp/cakephp/src/Validation/Validation.php:149
/shared/httpd/app/vendor/cakephp/cakephp/src/Validation/RulesProvider.php:92
/shared/httpd/app/vendor/cakephp/cakephp/src/Validation/ValidationRule.php:160
/shared/httpd/app/vendor/cakephp/cakephp/src/Validation/Validator.php:3184
/shared/httpd/app/vendor/cakephp/cakephp/src/Validation/Validator.php:262
/shared/httpd/app/vendor/cakephp/cakephp/src/ORM/Marshaller.php:286
/shared/httpd/app/vendor/cakephp/cakephp/src/ORM/Marshaller.php:212
/shared/httpd/app/vendor/cakephp/cakephp/src/ORM/Table.php:2959

Basically all fields set as such would have the argument cout error exception. And those are hundreds.

The Users Table is just setting the validation more dynamically.
So essentially

$rules = [
  'notEmpty' => [
    'rule' => 'notBlank',
    'message' => 'Pflichtfeld',
    'last' => true
  ],
  'minLength' => [
    'rule' => [
      (int) 0 => 'minLength',
      (int) 1 => (int) 3
    ],
    'message' => 'Mindestens 3 Zeichen',
    'last' => true
  ],
  'maxLength' => [
    'rule' => [
      (int) 0 => 'maxLength',
      (int) 1 => (int) 18
    ],
    'message' => 'Maximal 18 Zeichen',
    'last' => true
  ],
  'valid' => [
    'rule' => [
      (int) 0 => 'isValid'
    ],
    'message' => 'valErrInvalidChars',
    'last' => true,
    'provider' => 'table'
  ],

going into

$validator->add($field, $rules);

This worked in 5.0 and 5.1, and now stops with this hard fail.

I see that there have been some changes in
src/Validation/ValidationRule.php
Those might play into it.

This might also likely be the result of #17994 as side effect maybe

CakePHP Version

5.2

PHP Version

8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions