PrimitiveTypeConstraintValidator vs ConfigSchemaChecker: test coverage to establish the status quo

Created on 16 February 2024, about 1 year ago

Problem/Motivation

While working on πŸ“Œ Expose API to sort arbitrary config arrays Needs work (whose purpose is to be able to get a canonical representation of any config according to the config schema), two fundamental things were discovered:

  1. the values that are set are ARE the values that are saved βœ…
  2. the values that are validated ARE NOT the values that are saved ❌
  3. PrimitiveTypeConstraintValidator considers some values invalid prior to the magical casting that happens in \Drupal\Core\Config\StorableConfigBase::castValue(), and only thanks to this casting does the config not trigger errors in ConfigSchemaChecker ❌

Extra complication: the "trusted data" concept introduced by #2432791: Skip Config::save schema validation of config data for trusted data β†’ bypasses \Drupal\Core\Config\StorableConfigBase::castValue(). Which makes it the only way to trigger ConfigSchemaChecker errors for "primitives" (config schema types whose class implements PrimitiveInterface).

Note: the "trusted data" concept causes problems and πŸ“Œ Deprecate the trusted data concept in configuration Active aims to deprecate it.

Steps to reproduce

See tests added here.

Proposed resolution

Change NOTHING (it'd be too risky and complex to do in a single commit), but only add test coverage, to allow other issues to reconcile the inconsistencies.

Take special care to make πŸ“Œ Deprecate the trusted data concept in configuration Active simpler rather than harder: when that eventually is removed, it should be possible to trivially remove the test coverage specific to that.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 11 days ago

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Pipeline finished with Failed
    about 1 year ago
    Total: 519s
    #96911
  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Did not test but seems there is a failing kernel test.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Crediting phenaproxima for the reviews on the MR.

  • Pipeline finished with Failed
    about 1 year ago
    Total: 573s
    #98760
  • Status changed to Needs review about 1 year ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Pipeline finished with Success
    about 1 year ago
    Total: 470s
    #98780
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So the feedback appears addressed but will leave for @phenaproxima to take another look.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Looks pretty good but leaving at NR because I'm still not sure some of the commentary is as clear as it could/should be.

  • Status changed to RTBC 12 months ago
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    I think the comments are pretty good; in my opinion this is good to go.

  • Status changed to Needs review 12 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    It's really different to be triggering deprecations in a test and then adding generic ignores. This feels wrong and very odd. I'm not really sure what we're communicating here.

  • Status changed to RTBC 12 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    @alexpott did you see:

    # Temporarily while updating PrimitiveTypeConstraintValidator and ConfigSchemaChecker to agree with each other.
    # @todo Remove in https://www.drupal.org/project/drupal/issues/3230826.
    %The `type: (string|boolean|float|int)` config schema type uses magical casting when saving.%
    %⚠️ The `type: boolean` config schema type uses magical casting for the string value `(no|test|false|)` that is inconsistent with the validation logic in Drupal\\Core\\Validation\\Plugin\\Validation\\Constraint\\PrimitiveTypeConstraintValidator.%
    %⚠️ The `type: (int|float)` config schema type uses magical casting for the string value `(55\%|)` that is inconsistent with the validation logic in Drupal\\Core\\Validation\\Plugin\\Validation\\Constraint\\PrimitiveTypeConstraintValidator.%
    %⚠️ The `type: (int|float)` config schema type uses magical casting for the boolean value `` that is inconsistent with the validation logic in Drupal\\Core\\Validation\\Plugin\\Validation\\Constraint\\PrimitiveTypeConstraintValidator.%
    

    ?

    The reason this MR is adding generic ignores is to allow this issue to be tightly scoped to ONLY documenting the current behavior in explicit tests. That then enables πŸ“Œ Expose API to sort arbitrary config arrays Needs work to remove the magic (i.e. not just documenting current behavior, but making it consistent), modify the expectations of the tests added here, and remove the generic ignores.

    The generic ignores do not negatively impact anyone? But they do allow this pure-test-coverage issue to help unblock the much more complex πŸ“Œ Expose API to sort arbitrary config arrays Needs work πŸ˜‡

  • Status changed to Needs work 12 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡³πŸ‡ΏNew Zealand luke.stewart

    Just noting that #2142995 might have some overlap here?

Production build 0.71.5 2024