Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
On a particular site, config whose original value has a line like
offset: 1
has been modified to instead look like
offset: !!float 1
When you run the config report, this config item shows up as changed (correct), but the diff shows up as empty (no differences, which is incorrect).
Proposed resolution
Figure out why the diff isn't working correctly and fix it.
Remaining tasks
TBD
User interface changes
Diff will work correctly.
API changes
Shouldn't be any.
Data model changes
I don't think so.
Original report...
The attached config is always displayed as changed.
I guess it is because the "!!float" marker.
Comment | File | Size | Author |
---|---|---|---|
#20 | 3002165-with-test-update-v2.patch | 1.68 KB | jhodgdon |
| |||
ckeditorheight.settings.yml | 44 bytes | Pasqualle |
Comments
Comment #2
jhodgdonThat's interesting!
It doesn't look like well-formed YML actually. When I run it through this YML validator
http://www.yamllint.com/
it removes some of the code and I get
So that is probably the problem. I think the YAML needs to have the !!float 2 in quotes. I'm not sure what happens when it is read in via Drupal's YML parser?
Comment #3
PasqualleThe config seems to work correctly with the ckeditorheight module.
Comment #4
jhodgdonWhat does it look like if you export it -- does it export looking the same as the input YAML file?
Comment #5
Pasqualleyes, actually the attached file was created from export
Comment #6
jhodgdonOK, thanks for all the information! We'll need to investigate what is happening, look at the diffs that are reported by this module, etc.
Comment #7
PasqualleTried to find another example for !!float. Found this on in core:
https://cgit.drupalcode.org/drupal/tree/core/modules/options/tests/optio...
but after importing this config, it does not show up as changed. Strange..
Comment #8
jhodgdonThe thing that looks possibly malformed to me is that there are spaces in the value, but it's not in quotes. I thought that YAML values with spaces in them needed quotes. Maybe not though.
Another thing you could do, since the module is reporting it is changed, is look at the differences the module reports.
Comment #9
jhodgdonNo, I'm wrong about that. The YAML specs
http://yaml.org/spec/1.2/spec.html
show that you can put scalars after : without quotes.
Comment #10
jhodgdonCan you provide steps to reproduce in the issue summary -- in particular, which project/module/theme/etc. would I need to install to see this happening? Thanks!
Comment #11
PasqualleOk, I have found the issue:
The CKEditorHeight module has its config without !!float.
So the original config is:
Config stored/exported as:
Because of this the config file is listed on the Reports page, even the Config diff page shows no difference.
I guess the Reports page should not list such changed config. Or do you think the original config must be fixed (to include !!float)?
Comment #12
jhodgdonUm. So it looks like the stored/exported config in your database is different from the config file in modules/CKEditorHeight/config/install, right? So it should be listed as different -- it sounds like the report is correct? But then you're saying that if you see it in the report and click to the diff, it shows no differences -- if that is true, it sounds like the bug is that no differences are reported?
Or did I misunderstand what you were saying in #11?
Comment #13
Pasqualleyes, the only difference is the missing !!float and the diff does not catch that.
Comment #14
jhodgdonWell, that's very interesting. So what we really need to investigate is why that config is not caught by the diff code. Suspicious that the validator I pointed to in #2 also somehow fails to read the !!float...
Fixing issue title/summary.
Comment #15
jhodgdonI debugged this today, and learned that that !!float in YAML encoding just means that the YAML value is a float 2.0 number in the active config in this example, not an integer 2 number as in the module-provided config.
So, what's happening is that on the report page, the module and active config are marked as different, because it uses === to compare the config, and 2.0 float is not === 2 integer. So, that is the correct answer.
But when you click through to the diff listing, the code in ConfigDiffer.... What it does it (a) normalizes config (which is also done when doing a 'is this the same' comparison) and then (b) converts it to text and then (c) does a diff on the text. But in step (b), when it printed the values for each key, it was just printing the value however PHP would print it, instead of YAML encoding it, so it was printing out "2" (without quotes) for both integer and float, and thus it doesn't show any difference when comparing the text output in (c).
Hope that made sense...
Here's a patch that should fix it (which may clarify what is/was being done). Let's see what the tests say... We may have to adjust some of them for the slightly different formatting. As a note, the Yaml::encode() function handles NULL values, so I took out that elseif too.
Comment #17
Pasquallereally excellent investigation!
Comment #18
jhodgdonAs I suspected might happen, we need a small test update, because we tested formatting and the output format changed a bit with this patch. Here's a new patch (interdiff is the Test part of the patch).
Comment #20
jhodgdonWell, that wasn't quite right! One more test fix, having to do with formatting our normalized config better...
Comment #21
jhodgdonOK, the tests pass this time... Reviews, anyone?
Comment #22
PasqualleThe problematic diff is now nicely displayed after applying this patch.
Comment #23
jhodgdonGreat, thanks for testing!
As this is changing the behavior of ConfigDiffer, and some other modules (Features?) use it, I'll leave this at RTBC for a week or so before committing, in case anyone wants to comment/test.
Comment #25
jhodgdonThis has waited long enough. Thanks again for all the testing/collaboration on this! Committed.