Updated as of comment #50
Problem/Motivation
In #2921810: Allow TimestampFormatter to show as a fully cacheable time difference with JS, a time diff formatting option was added. Part of that implementation was a "fallback configuration", labeled 'description'.
It is a #type item element that only introduces the settings shown below it, but Form API treats that type as an input, so an empty value is collected on submit and stored in the formatter settings.
The stored value has no schema, since a label is not a setting, so validation fails wherever configuration is checked, whether by enabling config.schema_checker in development.services.yml, using config_inspector, or running tests:
Schema errors for core.entity_view_display.entity_test.entity_test.default with the following errors: core.entity_view_display.entity_test.entity_test.default:content.field_timestamp.settings.time_diff.description missing schema, 0 [content.field_timestamp.settings.time_diff.description] 'description' is not a supported key.
Steps to reproduce
- Add a timestamp field to an entity view display, or to a view.
- Set its formatter to Default (timestamp) and save the formatter settings.
- Export the configuration.
Expected: only the formatter's own settings are stored.
Actual: time_diff also contains an empty description.
Proposed resolution
Set #input to FALSE on the label, so Form API does not collect a value for it and it is never written to config. This is MR !9250.
Remaining tasks
Decide whether an upgrade path is needed to remove the key from configuration that already has it. See #47 for why a complete one is difficult, and why re-saving the formatter settings clears it anyway.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #54 | core-3400522-54.patch | 4.53 KB | dpacassi |
| #45 | 3400522-45.diff | 842 bytes | herved |
| #40 | core-3400522-time_diff-missing-schema.patch | 575 bytes | tiagoz |
| #28 | core-3400522-28.patch | 1.29 KB | graber |
| #9 | views.view_.time_diff_test.yml | 6.28 KB | agentrickard |
Issue fork drupal-3400522
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
heddnComment #5
boobaaComment #6
smustgrave commentedCan the rest of the issue summary be filled in please.
Also change caused test failures.
Comment #7
boobaaComment #8
heddnObviously we need tests added or this wouldn't have passed any if there were any. Tagging.
Comment #9
agentrickardHere's a simple view that shows the issue -- let me see if I can work up an MR.
Comment #10
agentrickardOK, here's what I did.
core/modules/node/tests/modules/node_test_views/test_views/views.view.test_field_created.ymlIf I read the code from
core/modules/node/tests/src/Functional/Views/NodeTestBase.php, the setup() method should try to import the new view and then auto-fail schema checks.If this test fails as I expect, then we can re-commit the patch.
Comment #11
smustgrave commentedThere's a test-only feature so don't need to push separately.
Comment #12
agentrickardWell, I suspect this minor issue may be covering up a more major problem (which we should file separately).
This is the YML from the test file:
This is the YML from core views.view_content
When the schema change was made in core, the affected core views were not updated. The following core views are potentially affected:
What does this potentially mean?
If the affected core views had been updated with the original change was made, tests would have caught the issue.
Comment #13
agentrickardHere's an updated MR that does the following:
* Removes the new test file
* Adds the `description` element to `views.view.content.yml`
Comment #14
agentrickardUpdate:
* This merge shows the issue (and the test fails) https://git.drupalcode.org/project/drupal/-/merge_requests/5505/diffs?co...
* Re-added the original patch / change
* Updated all affected views
Comment #15
smustgrave commentedSeems to have failures
But if we are updating all views will need an upgrade path for existing sites
Also not sure the title reflects what the MR is doing so tagged for that.
Comment #16
anybodyConfirming this issue, we just ran into it. Resaving the view adds the empty string.
Comment #18
haydenhuffman commentedI will update the title based on the MR and confirm the steps in the updated summary by EOD Monday 2024-07-29.
Comment #19
haydenhuffman commentedTitle updated, removing tag.
Comment #20
haydenhuffman commentedComment #21
haydenhuffman commentedSummary updated, removing tag.
Comment #22
sorlov commentedAdded hook_post_update_NAME() to update existing views with description for time_diff for timestamp formatter
need review
Comment #23
smustgrave commentedSee upgrade path but still needs upgrade test.
Comment #24
andypostComment #25
andypostThe test is incomplete but please combine it with checking that field is propagated after upgrade, so we can get rid of "Needs test" tag
Comment #26
graber commentedMaybe I'm missing something but:
Drupal\Core\Field\Plugin\Field\FieldFormatter::settingsForm()Description is just a user information element, it doesn't need a schema, how come it got to form state values and exported config in the first place?
Comment #27
graber commentedChanging this to:
fixes the config after save in views. So the issue is that "item" form element value gets to form state values as an empty string instead of not being passed there at all. On the other hand when saving on entity display settings form, description is not in the config (maybe there's a empty value filter).
And we need to get rid of those 'description' config values in time_diff everywhere.
Comment #28
graber commentedI'd do this. It's a very deep core form API change so let's see if it doesn't break anything.
Comment #29
graber commentedCreated #3467091: Item (display only) element results in an empty string in form_state values that addresses the root cause. Unfortunately, a few tests fail so it's not going to be that easy.
Comment #31
sorlov commentedOpened separate MR https://git.drupalcode.org/project/drupal/-/merge_requests/9250 for another solution
Issue was fixed by adding
'#input' => FALSE,to$form['time_diff']['description']So now we won't have empty
descriptionkey in formatter configComment #32
graber commentedNice one, but shouldn't we fix it in a more global way, adding it to item element defaults instead?
Comment #33
smustgrave commentedIf a new solution is used will need to update the issue summary, maybe? the title also.
Would need to check the criteria to see if this change is small enough to warrant not needing test coverage
Comment #34
andypostNew workaround point to problem with
itemform element inside of forms, git research points to #1825044: Turn contact form submissions into full-blown Contact Message entities, without storageSo I think if no other option to replace the element with
#markupfor example the !5505 looks nice idea but surely it needs follow-up to prevent export of this element to config at all, maybe event remove it at form state level via #3467091: Item (display only) element results in an empty string in form_state valuesPrevious code was
Comment #35
andypostIssue could be considered a duplicate if hack with input will be moved to contact module in #3467091: Item (display only) element results in an empty string in form_state values
Comment #36
sorlov commentedI'm not sure if this is global issue, related to any item element, cause for example, we have a lot of item elements in FileSystemForm form, but they are not exposed to config values
Comment #37
emptyvoid commentedJust updated code base to 11.2.0 and during database update got a long list of schema errors in almost all of the 50+ views in the system. And promptly both the admin views and interfaces and key site features generate 500 errors or white screens of death.
Except, I get 500 errors and white screens of death.. so not trivial.
I'd provide some details based on errors, but this issue white screens the dblog view so...
Reviewing the apache log directly it shows the same information bubbling up from the Drupal framework.
Warnings..
However, manually exporting the config for the view the fields and settings are exported with defaults.
Comment #38
emilorol commentedApplying path #28 solved the problem for me after resaving the field and then the view again without changing any of the two.
Some other warnings too about sequence as well after upgrading core to 11.2.1
Comment #39
tiagozturning #31 MR into patch
Comment #40
tiagozComment #41
ivnishWe need to choose one solution here
Comment #42
hitchshockMy opinion on this matter is as follows:
The patch #28 is more risky and dependent on many things on the site, and it's also a duplicate of #3467091: Item (display only) element results in an empty string in form_state values. We should leave this decision on hold on that ticket until it has been covered by tests and we are sure that it will not cause any new problems.
The solution from #30 just fixes an old issue, so it looks much better for me. And we can be sure that nothing else will be affected.
But, the patch is not ready yet. We need:
- a test that confirms that the issue exists and is now fixed
- upgrade path, to remove 'description' from the existing configs. Why? Because #2921810: Allow TimestampFormatter to show as a fully cacheable time difference with JS was released in 2023, and many configurations already contain this unexpected “description” property
Comment #45
herved commentedRebased MR 9250, attaching snapshot.
Comment #46
francismak commentedTested patch from #45 and description is gone during config export and no more warning in Drupal 11. Thx!
Comment #49
herved commentedI rebased the MR and added a test that fails without the fix.
On the upgrade path from #42, I would propose we skip it.
Covering it properly means more than
entity_view_displaycomponents: the same settings live in Layout Builder sections, in views field handlers, and in anything else that embeds a formatter. A partial update is arguably worse than none, since sites would assume the problem was handled.The key is inert at runtime anyway, and only surfaces where configuration is validated strictly, which is how this was reported. It also clears itself when the formatter settings form is re-saved, since the settings are rebuilt from the submitted values.
Does skipping the upgrade path seem reasonable?
Comment #50
herved commentedI updated the issue title and summary for the chosen approach.
Moving to review, for feedback on #49.
Comment #51
meeni_dhobale commentedI tested the latest MR (!9250) against Drupal core main, PHP 8.5, and it solves the issue. The schema error on time_diff.description is gone after applying it. Reverted just the fix line to double check, and the bundled test failed without it, passed with it. Looks good to me.
Regression checks (health check, module compatibility) passed too.
Still, the question raised in #49 about skipping the upgrade path remains open.
Comment #52
smustgrave commentedThink this is a good example to switch to kernel test, also is there an existing test that we could expand?
Comment #53
herved commentedIndeed, done.
Not really, the nearest candidate is core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php, but is a rendering test.
Comment #54
dpacassiAdding a static patch file from the current MR/diff.
Tested it in a Drupal 11.3 site, everything works as expeted.
A small note though: If you config export before applying the patch, the config will contain the description key.
You'll have to save the forms with that config again and export the config again to have it removed.
(Not saying we should also take care of that, just hinting at this)