Problem/Motivation

Comes from #2422013: Integrity constraint violation - Column 'comment_status' cannot be null

Generating default Article nodes with devel_generate produces the following error:

Integrity constraint violation: Column 'comment_status' cannot be null

Looks like the issue is because CommentItem is not overriding generateSampleValue().

Proposed resolution

Add generation of status property that actually stored in field, see CommentItem::schema() and CommentItem::propertyDefinition() that mark only status as required.

Remaining tasks

  • Write a patch
  • Review

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

penyaskito’s picture

Status: Active » Needs review
FileSize
913 bytes

This fixes the issue, but I don't think is the proper fix.

Manuel Garcia’s picture

Just confirming... with both this patch and the one on the devel_generate thread, devel_generate works again :)

willzyx’s picture

Title: Integrity constraint violation - Column 'comment_status' cannot be null when generating nodes with comments with devel_generate » CommentItem should override the generateSampleValue method and provide sample values
Issue summary: View changes
clemens.tolboom’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This needs a test like done in \Drupal\datetime\Tests\DateTimeItemTest. I checked for CommentItemTest.php but there is none.

cd core/module
grep -r generateSampleValue *
grep -r " extends FieldItemBase" *
pcambra’s picture

Status: Needs work » Needs review
FileSize
5.06 KB
5.08 KB

Looking into this, the issue comes a little upstream, comments are not created the same way that the rest of the fields.

This will need some more work in terms of how to be able to pass the entities to generateValues without breaking the interface and also pool the author of the comment from the existing users.

Here's a patch in the good direction, I think

Manuel Garcia’s picture

Status: Needs review » Needs work

Content seems to be generated fine (using patch #3 from devel_generate issue), but when I visit a node with comments, I see this fatal error:
Fatal error: Call to a member function label() on a non-object in /var/www/drupal8/core/modules/comment/src/Entity/Comment.php on line 402

andypost’s picture

Status: Needs work » Needs review
FileSize
971 bytes

This code is enough to make devel work (tested)
Probably needs to extend with other fields from CommentItem::propertyDefinitions()

  1. +++ b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php
    @@ -193,4 +196,29 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
    +  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    ...
    +      $values = array(
    +        'entity_type' => $field_definition->getTargetEntityTypeId(),
    

    this is totally wrong

  2. +++ b/core/modules/comment/src/Tests/CommentItemTest.php
    @@ -0,0 +1,89 @@
    +    $entity = entity_create('entity_test');
    +    $entity->comment->generateSampleItems();
    

    that's enough to make sure other properties of the field populated

  3. +++ b/core/modules/comment/src/Tests/CommentItemTest.php
    @@ -0,0 +1,89 @@
    +      $entity->save();
    

    any reason to save?

willzyx’s picture

@Manuel Garcia
note patch #3 from devel_generate issue fix only devel_generate tests

@andypost
i agree with you #7 should enough to make devel work but probably we needs to extend generateSampleValue with other fields from CommentItem::propertyDefinitions.. and I think we still need test coverage for CommentItemTest

andypost’s picture

Issue tags: -Needs tests
FileSize
1.81 KB
2.75 KB

So here's a test and test+patch

andypost’s picture

No reason to extend because only status property is stored in field, others are populated on load

andypost’s picture

FileSize
2.11 KB
3.06 KB

oh, previous patches are wrong

The last submitted patch, 11: 2422101-comment-generate-11-test-only.patch, failed testing.

willzyx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC for me

clemens.tolboom’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php
@@ -193,4 +194,13 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
+      'status' => mt_rand(CommentItemInterface::HIDDEN, CommentItemInterface::OPEN),

This assumes ordered values which might change in the future. Better use something inline with

$statusses = array(CommentItemInterface::HIDDEN, CommentItemInterface::OPEN);
$status = $statusses[mt_rand(0, count($statusses)-1];
andypost’s picture

Status: Needs work » Needs review
FileSize
849 bytes
3.17 KB

@clemens.tolboom Nice catch! Fixed

andypost’s picture

Issue tags: +Contributed project blocker
Fabianx’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

RTBC, works great!

Major because generating content is crucial for proper benchmarking.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Are we going to address the other properties in a followup or in this issue? I would have though generating content with comments is crucial for proper benchmarking?

clemens.tolboom’s picture

This needs a summary update explaining what we do with

CommentItem::propertyDefinitions
andypost’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs issue summary update
Related issues: +#2304939: Stop loading comment statistics into entity object

@alexpott comment field have only one status property, other properties are populated in runtime and there's #2304939: Stop loading comment statistics into entity object

Fixed summary.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0972ecb and pushed to 8.0.x. Thanks!

  • alexpott committed 0972ecb on 8.0.x
    Issue #2422101 by andypost, pcambra, penyaskito: CommentItem should...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.