Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error doesn't contain expected fields #7945

Closed
dmitryuk opened this issue Oct 14, 2022 · 3 comments · Fixed by #7949
Closed

Validation error doesn't contain expected fields #7945

dmitryuk opened this issue Oct 14, 2022 · 3 comments · Fixed by #7949

Comments

@dmitryuk
Copy link
Contributor

dmitryuk commented Oct 14, 2022

Environment

Sonata packages

show

Direct dependencies required in composer.json:
sonata-project/admin-bundle              4.19.0 4.19.0 The missing Symfony Admin Generator
sonata-project/doctrine-orm-admin-bundle 4.8.0  4.8.0  Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.13.0 3.0.0  Lightweight Exporter library
sonata-project/media-bundle              4.5.1  4.5.1  Symfony SonataMediaBundle

Transitive dependencies not required in composer.json:
sonata-project/block-bundle              4.18.0 4.18.0 Symfony SonataBlockBundle
sonata-project/cache                     2.2.0  2.2.0  Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       2.0.1  2.0.1  Doctrine2 behavioral extensions
sonata-project/form-extensions           1.18.0 1.18.0 Symfony form extensions
sonata-project/twig-extensions           1.12.0 2.0.0  Sonata twig extensions

Symfony packages

show

Direct dependencies required in composer.json:
symfony/monolog-bundle           v3.8.0  v3.8.0  Symfony MonologBundle
symfony/phpunit-bridge           v4.4.44 v6.1.6  Provides utilities for PHPUnit, especially user deprecation notices management
symfony/symfony                  v4.4.46 v6.1.6  The Symfony PHP framework

Transitive dependencies not required in composer.json:
symfony/contracts                v1.1.13 v3.1.1  A set of abstractions extracted out of the Symfony components
symfony/deprecation-contracts    v3.1.1  v3.1.1  A generic function and convention to trigger deprecation notices
symfony/polyfill-ctype           v1.26.0 v1.26.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme   v1.26.0 v1.26.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu        v1.26.0 v1.26.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn        v1.26.0 v1.26.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.26.0 v1.26.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring        v1.26.0 v1.26.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72           v1.26.0 v1.26.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73           v1.26.0 v1.26.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80           v1.26.0 v1.26.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81           v1.26.0 v1.26.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/security-acl             v3.3.2  v3.3.2  Symfony Security Component - ACL (Access Control List)
symfony/string                   v5.4.13 v6.1.6  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters i...
b

PHP version

8.1

Subject

Steps:

  • Frontend makes ajax request
  • Backend generates validation error and handle it here
  • FormErrorIteratorToConstraintViolationList::transform generates list of violations ConstraintViolationListInterface
  • $this->json goes result to the code (ControllerTrait)
$this->container->get('serializer')->serialize($data, 'json', array_merge([
                'json_encode_options' => JsonResponse::DEFAULT_ENCODING_OPTIONS,
            ], $context))
  • $data normalized in \Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer
result translates to response (slider)

{"type":"https:\/\/symfony.com\/errors\/validation","title":"Validation Failed","detail":"s63492c556297a[media_en][translation]: Media with this filename already exists","violations":[{"propertyPath":"s63492c556297a[media_en][translation]","title":"Media with this filename already exists","parameters":{"{{ value }}":"\u00222--[en]\u0022"},"type":"urn:uuid:23bd9dbf-6b9b-41cd-a99e-4844bcf3077f"}]}

  • Frontend tries to read result here, but it doesn't contain message and errors, but has title and violations
@VincentLanglet
Copy link
Member

@jordisala1991 recently changes the validation errors here: #7922

Can you provide a PR to update the frontend code with the news keys ? @dmitryuk

@dmitryuk
Copy link
Contributor Author

dmitryuk commented Oct 14, 2022

#7946

@jordisala1991
Copy link
Member

#7949 This is the last piece to close the issue.

@jordisala1991 jordisala1991 linked a pull request Oct 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants