Problem/Motivation
#2361539: Config export key order is not predictable for sequences, add orderby property to config schema introduced \Drupal\Core\Config\Schema\SequenceDataDefinition, a subclass of \Drupal\Core\TypedData\ListDataDefinition which was used until then.
This new class was associated with the sequence config schema type. Everything's been working fine.
But because the new SequenceDataDefinition did not override \Drupal\Core\TypedData\ListDataDefinition::getDataType(), the returned data type is still wrong.
This has not mattered in the >10 years that have passed since #1866610: Introduce Kwalify-inspired schema format for configuration introduced the concept of config schemas nor in the almost 9 years since #2277945: Typed configuration implements TypedDataInterface improperly added typed data integration:
sequence:
label: Sequence
class: '\Drupal\Core\Config\Schema\Sequence'
definition_class: '\Drupal\Core\TypedData\ListDataDefinition'
… but then again:
\Drupal\Core\TypedData\ListDataDefinitionis atypical because it overrides the inherited\Drupal\Core\TypedData\DataDefinition::getDataType()which would've returned the correct value- It's only now that we're getting serious about config validation (see #2164373: [META] Untie config validation from form validation — enables validatable Recipes, decoupled admin UIs …), which is why I discovered it in #3216089: Expose validation constraints (and validatability %) in Config Inspector UI.
Steps to reproduce
N/A
Proposed resolution
Tests + fix.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3361034-3.patch | 1.9 KB | wim leers |
| #3 | 3361034-3-test-only-FAIL.patch | 1.31 KB | wim leers |
Comments
Comment #2
wim leersOops! 😅
Comment #3
wim leersComment #4
wim leersDiscovered this in #3216089: Expose validation constraints (and validatability %) in Config Inspector UI and hence had to work around this.
Comment #5
wim leersHow the hell did you run into this?
I worked around it in contrib like this:
… because without this, it's impossible to correctly traverse a typed data tree by using the return value of
$typed_data->getDataDefinition()->getDataType()… sincelistis not actually a config schema type,\Drupal\Core\Config\TypedConfigManager::determineType()decides to make it automagically fall back to theundefinedtype 😳… at which point traversing further down the three of course is impossible.
Why can this go undiscovered for a decade?
The reason this has not caused problems for Drupal core so far is that
\Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validateNode()does not use the full config schema tree, but instead relies on inspecting the typed data's object instances:Comment #6
borisson_Super interesting bug, good find. Are the other TypedData classes correct?
Comment #7
wim leersFieldConfigBase::getDataType()is wrong too:… but I figured we'd keep this tightly scoped, because that is one of the most complex pieces of config 😱
Comment #10
borisson_Looks like a random failure to me
Comment #11
quietone commentedTriaging the RTBC queue.
What a easy issue to triage! The IS is clear and enjoyable to read. The situation is further explained in comment #5. I also agree with the scoping. All questions have been answered.
The only thin I see that it does appear this a followup is needed for #7.
I have updated the title to explain what is being changed.
Comment #12
wim leers#11 That's LOVELY to hear! 😊😊 Glad to read it helps and is appreciated!
New issue created, with a lot more detail than was present in #7: #3370179: Clarify why FieldConfigBase::getDataType() is 'list' and not 'field_config_base'.
Comment #13
fagoGood find! Yes, the typed-data implementation of config wasn't focused enough on implementing its contract cleanly.
The fix is straight forward, the right thing todo and comes with test! I second the RTBC!
Comment #14
lauriiiDiscussed with @longwave and @fago and agreed that we should write a short change record for the behavior change here.
Comment #15
fagoI've added a change record draft
Comment #18
lauriiiCommitted 89ac074 and pushed to 11.x. Thanks!