Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
node system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Aug 2023 at 16:01 UTC
Updated:
16 Feb 2024 at 09:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
phenaproximaWell, that was easy. Assigning to Wim for review.
Comment #4
wim leershelpanddescriptionneed validation constraints too. It's not that because they're optional that we accept any value for them.I'd like to see explicit test coverage for trying to set
preview_modetonull, because I'm not sure if that would be cast to0during validation at some point? 🤔They're
type: text… do we want invisible control characters (think \x08 for backspace: https://www.asciitable.com/) to be accepted?Opened #3379102: Add validation constraint to `type: label` + `type: text`: disallow control characters for this.
Comment #5
phenaproximaI mean...I agree, but what constraints would you have me add here? Both are optional text fields. They are already using the
textdata type. I agree that we want to disallow control characters, but I also agree that's not in scope here, and should be done in a separate issue.I guess we could at least add
NotNull.Great catch! This revealed the need for a
NotNullconstraint onpreview_mode.Comment #6
wim leersMaking
helpanddescriptionnot nullable implies making them required? 😅Comment #7
phenaproximaWouldn't they be empty strings? That's distinct from NULL.
Comment #8
wim leersYes, but IIRC
\Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator::validate()automatically maps''toNULL🤓Comment #9
phenaproximaRe #8: that's not accurate.
\Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator::validate()maps empty values to NULL...forListInterfaceandComplexDataInterfaceonly.Plain strings don't implement those interfaces (although string field items do). Meanwhile, the parent class of that validator strictly checks for NULL.
So,
NotNullis a reasonable choice forhelpanddescription.Comment #10
wim leers#9: Oops, you're right! I was confusing it with
StringItemwhich does implementComplexDataInterface. Since this is (typed) config, this isStringDatainstead. My bad!But … I don't think defaulting
helpanddescriptionto the empty string makes sense? That means we'd end up withnode.type.*.ymlfiles containing:Wouldn't it then be clearer to have this instead?
IOW: I think
NotBlankwould be conceptually more clear thanNotNull. Requiring a value (i.e. not NULL) but then accepting the empty string feels rather odd to me? 🥸Comment #11
phenaproximaNotBlank is a no-go: that means description and help will become required, rather than optional. Changing the defaults to empty strings is correct — there is default config in core with empty strings for those keys.
Comment #12
wim leersI'm questioning whether that default config makes sense.
Comment #13
phenaproximaOkay, Wim, I think you've convinced me (on Slack, that is). Let's postpone this issue on #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support and make those fields nullable.
The solution you proposed (which I think is good) is:
Comment #14
wim leersTo allow other Drupal contributors to actually grok #13:
@phenaproxima wrote in Slack, in response to #12:
to which I responded this:
The point is that
description: ''(the empty string) makes it seem like there’s an actual description present, but there isn’t. All we’ve done is satisfy the requirement that it’s a string.So on the one hand it’s a “required” value (because we’re not allowing
null, which is why you changed it to''in your latest commit).This conveys “every Node Type MUST have a description”. Okay! 👍
But on the other hand we allow a value that is completely pointless, because the empty string is NOT a reasonable description! 👎
That’s why I’m saying it would be clearer to have
description: null, because that at least makes it clear that it is indeed optional.Any time something is optional, it should allow
null. That’s literally why\Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints()has:IMHO the correct solution is:
NotBlank→ empty string is not allowed, because that’s nonsensicalNotNull\Drupal\node\Entity\NodeType::getDescription()(the Entity API-level representation) to return the empty string if the config-level representation containsnull, to avoid a BC break.Comment #15
wim leersFYI this is itself also a blocker, for #3379091: Make NodeType config entities fully validatable.
Comment #16
wim leersLet’s continue this issue, because there’s nothing stopping us from rebasing that MR on top of a squashed commit of its blocker’s (#3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support) MR! 🤓
If we can get this to green or even RTBC, then it becomes more likely that the blocker (which has been RTBC for exactly 3 weeks now) gets committed! 🤞
(Also: it's clear that #3324140: Convert field_storage_config and field_config's form validation logic to validation constraints is full of dragons 🐲 that jump out of every crevice 🐉 — so getting this one config entity type to fully validatable is much more realistic and would still be a huge leap forward!)
Comment #17
phenaproximaComment #18
wim leersThis is impossible to review right now, because I can't create a diff relative to #3379091: Make NodeType config entities fully validatable. To allow for such diffs, this must always:
origin/11.xSo, did that: started from latest 11.x, cherry-picked #3379091, then cherry-picked all of the individual commits by @phenaproxima one-by-one.
Comment #19
wim leersLooks great! 🤩
232 tests fail. Looks like many of them are due to a missing update path. For example when running
CKEditor5UpdateCodeBlockConfigurationTest, the failure is:That update logic should match the one at #3380480: Views should require a label, rather than falling back to an unhelpful ID.
Comment #20
phenaproximaHere's a review-only version of the patch which doesn't include the stuff in #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support.
Comment #21
phenaproximaFinally! Here's a review-only patch.
Comment #22
wim leersThat was fast! 😄 Way faster than I thought possible!
I have zero remarks whatsoever 😦😅🥳
I have only one bit of magnificent output to share:
(Fresh install of
11.xbranch, https://www.drupal.org/project/config_inspector installed, then switching to this MR, will give you that output.)Look at that!!! The first 100% validatable config entity type! 🤩🚀
Marking as a postponed RTBC until the blocker lands. Awesome work, @phenaproxima! 🙏
Comment #23
effulgentsia commentedSetting status to postponed since it's blocked on #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support which needs a rebase.
Comment #24
wim leersRe-reviewing this now that [#3364109 is getting closer …
The first line here will be necessary after #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support lands.
The last 3 lines:
type: text(see #3379102: Add validation constraint to `type: label` + `type: text`: disallow control characters for earlier issue) — but then again, this is likely to trigger other issues. Could we instead create a follow-up for doing that, and point at that issue with a@todofrom here to ensure we don't forget to update IF that happens? 🙏NotBlank: {allowNull: true}) with another issue: #3404061: When setting `NotNull` constraint on type: required_label, two validation errors appear.Comment #25
wim leersThanks to #3404061: When setting `NotNull` constraint on type: required_label, two validation errors appear having landed, this can now be changed to merely
👍
Comment #26
phenaproxima#3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support landed, so per #23 this is no longer postponed. Assigning to Wim for rebase and whatever updates are needed.
Comment #27
wim leersWhew, this ain't no simple rebase or merge! 😳
Catching this up on months of history and getting rid of the in-flux blocker that was merged in here but has now been merged upstream (see #26) is no easy task.
I came up with this:
gives me the commit hashes of all commits from this MR that I care about (I could also copy/paste them from https://git.drupalcode.org/project/drupal/-/merge_requests/4535/commits, but that is a LOT of clicking and back-and-forth).
Next, create a new branch from upstream
11.x:and then do an interactive rebase in which I paste the relevant commits that I want to port into the new branch (which is all of them except the ones that mention "merge"):
and then invert their order (CTRL+T on macOS), to paste them into the interactive rebase.
So then the interactive rebase looks like this:
Comment #30
wim leersThe new MR is green!
What does it contain?
::testNonNullableFields()test coverage @phenaproxima added, because that landed as part of #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support, where it was named::testRequiredPropertyValuesMissing()(which tests it in more detail and in a more robust way)FullyValidatableconstraint onNodeType, ii) explicitly declaredescriptionandhelpas having optional values, to allow::testRequiredPropertyValuesMissing()to passNotNullthanks to specifyingFullyValidatableat the root!I will RTBC this … once there is a change record. 😄
Comment #31
borisson_I agree with @Wim Leers, the open MR is looking great and the testcoverage that is added is great as well. The last nitpick should be simple to remove as well.
Do we need the change record for the added strictness to the schema (and will we need one for each entity type we make more strict as we go?), or what is it for?
Comment #33
wim leers@sourabhjain That's the second issue in a span of 10 minutes where you applied my suggestion manually locally and pushed it. Why are you doing that? 🤔
Comment #34
sourabhjainI apologize for any inconvenience, @wim-leers. I misunderstood the suggestion, thinking it was a provided task that anyone could work on. I will be more careful in the future and ensure that such misunderstandings don't happen again. Rest assured, everyone at Valuebound will be mindful of this.
Comment #35
phenaproximaChange record written: https://www.drupal.org/node/3409486
Comment #36
wim leersComment #37
phenaproximaComment #38
larowlanHiding patches
Comment #39
larowlanLeft a question on the MR, not changing the status
Comment #40
wim leersAddressed — keeping at RTBC because it was a trivial change.
Comment #43
larowlanCommitted to 11.x
Didn't backport to 10.2.x because this has an update path which is not allowed in patch updates.
Published change record.
Comment #46
wim leers