Problem/Motivation

As a developer, I want the output of

$ vendor/bin/drush config:inspect --detail --list-constraints

to tell me where validation must be added: on the actual type, or the inherited type.

Steps to reproduce

Today (if I remove the constraints on _core_config_info.default_config_hash):

$ vendor/bin/drush config:inspect --filter-keys=automated_cron.settings --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 
  Key                                                  Status    Validatable   Data   Validation constraints   
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 
  automated_cron.settings                              Correct   50%           ✅❓   ValidKeys: '<infer>'     
   automated_cron.settings:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'     
   automated_cron.settings:_core                       Correct   Validatable   ✅✅   ValidKeys:               
                                                                                        - default_config_hash  
   automated_cron.settings:_core.default_config_hash   Correct   NOT           ✅❓                            
   automated_cron.settings:interval                    Correct   NOT           ✅❓                            
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 

and

$ vendor/bin/drush config:inspect --filter-keys=block.block.olivero_syndicate --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  Key                                                        Status    Validatable   Data   Validation constraints                                                                       
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  block.block.olivero_syndicate                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                                                   
                                                                                              - default_config_hash                                                                      
   block.block.olivero_syndicate:_core.default_config_hash   Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies                Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:dependencies.module         Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies.module.0       Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: module                                                                      
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:dependencies.theme          Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies.theme.0        Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: theme                                                                       
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:id                          Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/^[a-z0-9_.]+$/'                                                                 
                                                                                              message: 'The %value machine name is not valid.'                                           
                                                                                            ↣ PrimitiveType: {  }                                                                        
                                                                                            ↣ Length:                                                                                    
                                                                                              max: 166                                                                                   
   block.block.olivero_syndicate:langcode                    Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                            Choice:                                                                                      
                                                                                              callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:plugin                      Correct   Validatable   ✅✅   PluginExists:                                                                                
                                                                                              manager: plugin.manager.block                                                              
                                                                                              interface: Drupal\Core\Block\BlockPluginInterface                                          
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:provider                    Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:region                      Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings                    Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:settings.block_count        Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.id                 Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.label              Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/([^\PC])/u'                                                                     
                                                                                              match: false                                                                               
                                                                                              message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:settings.label_display      Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.provider           Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:status                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:theme                       Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:uuid                        Correct   Validatable   ✅✅   Uuid: {  }                                                                                   
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:visibility                  Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:weight                      Correct   NOT           ✅❓                                                                                                
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 

Proposed resolution

Desired:

$ vendor/bin/drush config:inspect --filter-keys=automated_cron.settings --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 
  Key                                                  Status    Validatable   Data   Validation constraints                                                   
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 
  automated_cron.settings                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                     
   automated_cron.settings:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                     
   automated_cron.settings:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                               
                                                                                        - default_config_hash                                                  
   automated_cron.settings:_core.default_config_hash   Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: _core_config_info  
   automated_cron.settings:interval                    Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here                                
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 

and

$ vendor/bin/drush config:inspect --filter-keys=block.block.olivero_syndicate --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  Key                                                        Status    Validatable   Data   Validation constraints                                                                       
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  block.block.olivero_syndicate                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                                                   
                                                                                              - default_config_hash                                                                      
   block.block.olivero_syndicate:_core.default_config_hash   Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: _core_config_info                      
   block.block.olivero_syndicate:dependencies                Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:dependencies.module         Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   block.block.olivero_syndicate:dependencies.module.0       Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: module                                                                      
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:dependencies.theme          Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   block.block.olivero_syndicate:dependencies.theme.0        Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: theme                                                                       
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:id                          Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/^[a-z0-9_.]+$/'                                                                 
                                                                                              message: 'The %value machine name is not valid.'                                           
                                                                                            ↣ PrimitiveType: {  }                                                                        
                                                                                            ↣ Length:                                                                                    
                                                                                              max: 166                                                                                   
   block.block.olivero_syndicate:langcode                    Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                            Choice:                                                                                      
                                                                                              callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:plugin                      Correct   Validatable   ✅✅   PluginExists:                                                                                
                                                                                              manager: plugin.manager.block                                                              
                                                                                              interface: Drupal\Core\Block\BlockPluginInterface                                          
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:provider                    Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:region                      Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:settings                    Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:settings.block_count        Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.id                 Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.label              Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/([^\PC])/u'                                                                     
                                                                                              match: false                                                                               
                                                                                              message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:settings.label_display      Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.provider           Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:status                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:theme                       Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:uuid                        Correct   Validatable   ✅✅   Uuid: {  }                                                                                   
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:visibility                  Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:weight                      Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 

Note how _core.default_config_hash is simple (just one data/config schema type level up), but dependencies.module is not: the parent type is sequence, but adding constraints there does not make sense. They should be added one level higher, in config_dependencies.

A more extreme example of this can be found in core.entity_form_display.node.article.default, where we need to up multiple levels.

Remaining tasks

None.

User interface changes

At /admin/reports/config-inspector/core.entity_form_display.node.article.default/tree:

API changes

N/A

Data model changes

N/A

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new128.94 KB
new8.41 KB

I thought I was going to need parts of #3364108: Configuration schema & required keys, but … happy to say that was not needed!

Status: Needs review » Needs work

The last submitted patch, 2: 3391400-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

Interesting. I developed #2 against 11.x (aka upcoming 10.2.x), and that works fine. I can reproduce the test failures in #2 by switching to 9.5.x or 10.1.x 👍

wim leers’s picture

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.16 KB
new8.06 KB

Turns out I already added infra for this ~4 months ago in #3216089: Expose validation constraints (and validatability %) in Config Inspector UI, I just did not remember. Yay!

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Yay!

  • Wim Leers committed 87fa22b8 on 2.1.x
    Issue #3391400 by Wim Leers: Identify which properties must be made...
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Reviewed & tested by the community » Fixed

GitLab was very slow, but eventually accepted my push :D

wim leers’s picture

FYI:

$ vendor/bin/drush config:inspect --detail --list-constraints | grep "constraints to ancestor type" | wc -l
    4302

$ vendor/bin/drush config:inspect --detail --list-constraints | grep "csonstraints to config entity type" | wc -l
       0

$ vendor/bin/drush config:inspect --detail --list-constraints | grep "constraints to config entity type" | wc -l
    1000

$ vendor/bin/drush config:inspect --detail --list-constraints | grep "constraints here" | wc -l
     231

$ vendor/bin/drush config:inspect --detail --list-constraints | grep "@todo" | wc -l
    5533

4302+1000+231 = 5533 👍

And, performance is still fine:

$ time vendor/bin/drush config:inspect --detail --list-constraints | grep "@todo" | wc -l
    5533

real	0m3.533s
user	0m3.132s
sys	0m0.187s

(middle of 3 runs)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.