I have found a use case where it is possible to bypass any validation on any field within a paragraph. This basically allows to store values in the database that are not allowed by field settings.

Steps to reproduce:
1/ Create a paragraph with a numeric field and set the constraints to minimum 0, maximum 10.
2/ Create a content type and a paragraphs field with the classic widget on that content type that allows the paragraph from 1/
3/ Set the classic widget "Edit mode" to "preview". (this is the crucial bit, other modes work correctly)
4/ Create a node from the content type from 2/ and add a valid paragraph to it. Save the node.
5/ Edit the node, enter an invalid number in the numeric field in the paragraph (20 for example), collapse the paragraph and save the node.

After 5/ I would expect a validation error, but the node saves and the value "20" is stored to database.

If you set the "Edit mode" to something else then "preview" the paragraph can not be collapsed until the fields validate.

Issue fork paragraphs-3041810

Command icon 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

weseze created an issue. See original summary.

nikolaat’s picture

I have a node with Paragraph Entity field, where I can add multiple paragraphs. When I select first paragraph It is expanded and if I do not fill required fields and try to save, warring it not allowing me save the node.
But when I do not fill required field and add second paragraph, the first one paragraphs is shrank and its fields are not collapsed. If I fill the second paragraph correctly and try to save, the operation is successful and required field in paragraph one saved with empty value.
This is a big problem and I think first paragraph should be validated when try to add second.

supriya1992’s picture

Assigned: Unassigned » supriya1992
supriya1992’s picture

Hi,
I checked this issue on Drupal with paragraph 8.x-1.8 version. I follow your steps.
1. Create a paragraph with a number integer field make it required and also make min :0 and max: 10.
2. I used this paragraph inside a content type's field.
3. I try to create a node of this content type with wrong value ex: 34. It throw error and not allow to save the node.
4. When I edit the node and also try to save node with wrong numeric value again display error and not allowed to save the node.

I verify more than 3 times and get the same result. Can you check it again? And if you face the same issue then please uninstall this module and install freshly and use it.

weseze’s picture

Set the classic widget "Edit mode" to "preview". (this is the crucial bit, other modes work correctly)

supriya1992’s picture

Webbeh’s picture

+1, was able to reproduce this.

Webbeh’s picture

Assigned: supriya1992 » Unassigned

Unassigning this.

amaisano’s picture

This happened for me. I added two new paragraphs -- both in "Edit" mode -- with multiple required fields. While both paragraphs were in Edit mode, I went straight to the node Save button, and the page saved w/o any warnings or validation errors, despite the required paragraph fields being left empty. This seems fairly critical.

nejcramsak’s picture

Hi, i tried to replicate the issue but i wasn't able to. I set it to preview, but it always threw an error even if the field was collapsed when i tried to save the node. Is there something else that should be set?

liber_t made their first commit to this issue’s fork.

liber_t’s picture

Status: Active » Needs work

Step to reproduce:

  1. Add Paragraph (in this paragraph i have a required field)
  2. Add Secondary paragraph (The first paragraph is now collapsed)
  3. I have a deleted a Secondary paragraph
  4. I have a saved the node
  5. The node is saved but the required field in fist paragraph is empty

I have create an MR to fix nested paragraph but It's complicated to create functional test for me

jasa’s picture

I was able to reproduce following different steps.

1. Add Paragraph (with required fields).
2. Add Secondary Paragraphs (the first one is collapsed).
3. Then, I fill all required fields in for the second paragraph.
4. With the first paragraph collapsed, I click on "Save".
5. The node is saved, but first paragraph contains empty values for required fields.

This can be critical if you use preprocess functions as you get "Unexpected error" message.

As a workaround, I have developed a new "NotEmptyRequiredField" constraint function for paragraph entities, as if you create the constraint for specific fields, it will not work anyway in this case because you can keep editing collapsed paragraphs or create new ones without getting any error, so you are allowed to save the nodes.

jasa’s picture

I have checked @liber_t 's validation code.
It works (the node is not being saved), however required fields are not "marked" as wrong ones.

Using Experimental widget on paragraph entities.

liber_t’s picture

Assigned: Unassigned » liber_t
aaronelborg’s picture

I had originally posted about creating a constraint. I'm editing that post now.

I've found it hard to make a notEmpty constraint work with a taxonomy reference subfield of a paragraph inside a node. Particularly a Classic paragraph widget using 'preview' mode.

If the field's value has been cleared, the field's target_id still has the old value when the validate() method runs.

How can I check for an empty value? Is there some other signifier for the clearing of a field?

liber_t’s picture

Assigned: liber_t » Unassigned
leticia gauna’s picture

StatusFileSize
new2.09 KB

Hey, just create a patch with liber_t merge request 6, just tested the code and it's working fine!

sense-design’s picture

Patch cannot be applied anymore.