Needs work
Project:
Drupal core
Version:
main
Component:
user system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Dec 2016 at 15:08 UTC
Updated:
21 Jan 2023 at 02:02 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
hchonovComment #3
hchonovProviding a test proving that the user entity is not currently correctly validated on the user registration form.
Comment #4
hchonovBetter documentation.
Comment #7
hchonovI've created the constraint on the pass field, as the violations on the init field are filtered out because it is not part of of the list of editable fields.
@see \Drupal\user\AccountForm::getEditedFieldNames().
Comment #8
hchonovThis bug exists since Drupal 8.0.x.
Comment #9
hchonovComment #10
hchonovActivate the constraint only when required so.
Comment #16
berdirHm, this is a bit weird, though. We're validating something that we generated, that the user actually can't see or do anything about?
Also the class name here is wrong.
I understand the problem here and agree with the fix, but it would help to provide realistic test/example that actually makes sense. Can we have a constraint on it and disallow a certain e-mail there?
Can we add some asserts here to see what is happening on the form in this case?
Also, AFAIK we don't prevent validation errors to fields that are not visible.. or just fields that the user can't see? which might include init... mh...
How can the init field not exist?
Comment #17
hchonovI think I should not write patches when I am tired :). Most of the things are left overs from my initial approach of having a constraint on the "init" field in order to disallow certain email domains. The constraint on the "init" field worked and the constraint failed but the violation was filtered out as the "init" field is not amongst the editable fields in the form - the editable fields for which only the violations are shown are listed under AccountForm::getEditableFields and the "init" field is not amongst them. This is why I switched to a constraint on the "pass" field with an automatically generated password as this appears to be the only one testable approach. I agree that the current test is probably not realistic enough but at least it shows the problem of updating the entity in submit after it has passed the validation instead of validating the entity with the updated values. I will clean up the code tomorrow and will add an assertion that the validation error is shown after submitting the form.
However I think that the test here should be more for demonstrating the problem and probably only the fix should be committed.
Comment #18
hchonovComment #21
berdirHm. Technically, this slightly changes the behavior of this a bit without #2833682: In submit use the entity built during the validation instead of building it again - for performance and consistency ensuring we are saving the entity that has been validated, we call this multiple times and generate multiple passwords.
What if we change the code to set the values directly on the entity after building *and* only set it if they are not set yet, at least for the password?
Just thinking out loud, some more opinions from e.g. @tstoeckler would be great here.
Comment #22
hchonovI don't think that this is a "behavior change", it just shows that we need the other issue in as well :).
We could change the code but what is the point of reverting it in the other issue?
And also we cannot set and check an entity field as the entity is being built twice and in the second call of the entity builders we do not have the entity object generated from the first run, but a different one - so the field will not be set and we could use only the form state to temporarily store the password, which I would not do, as I don't see any reasons making it that complex.
Comment #23
hchonovComment #35
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Is this postponed on #2833682: In submit use the entity built during the validation instead of building it again - for performance and consistency ensuring we are saving the entity that has been validated?
Tagging for IS for remaining tasks after 6 years.