Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new2.66 KB
wim leers’s picture

StatusFileSize
new860 bytes
new3.49 KB
dawehner’s picture

I just had a look at the table itself: `entity_type` varchar(32) CHARACTER SET ascii DEFAULT NULL,
this means that setting it required would also have to be reflected in the schema itself, right?

dawehner’s picture

Status: Needs review » Needs work
wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new790 bytes
new3.49 KB

AFAICT this should do that.

Status: Needs review » Needs work

The last submitted patch, 6: 2885809-6.patch, failed testing. View results

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new4.84 KB
new1.6 KB

The test seems to prove you wrong.

Status: Needs review » Needs work

The last submitted patch, 8: 2885809-8.patch, failed testing. View results

dawehner’s picture

After some debugging it turns out #2841291: Fix NOT NULL handling in the entity storage and 'primary key' changes when updating the storage definition of an identifier field would be needed to automatically change it from NOT NULL FALSE to NOT NULL TRUE, because \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getSharedTableFieldSchema doesn't take into account the required setting.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB
new1.29 KB

Here is a small fix to ensure the query in the test actually works with a table prefix.

Status: Needs review » Needs work

The last submitted patch, 11: 2885809-11.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new5.04 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 15: 2885809-11.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

Not quite sure why we need to specifically make it storage required?

Just posting an alternative patch here from #2975217: Update the default comment entity owner to the current user for now that makes entity_type and field_name regular-required, which doesn't require an update path as it has no effect on storage and also makes the comment name validator more resilient on incomplete data.

Fine if we want to make it storage-required for some reason and combine the two patches, just want to move my patch out of that other issue.

interdiff is against the past patch over there.

berdir’s picture

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

makes entity_type and field_name regular-required, which doesn't require an update path as it has no effect on storage and also makes the comment name validator more resilient on incomplete data.

This sounds like music to my ears!

+++ b/core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php
@@ -291,35 +291,17 @@ public function testPostDxWithoutCriticalBaseFields() {
-    // @todo Uncomment, remove next 3 lines in https://www.drupal.org/node/2820364.
-    $this->assertSame(500, $response->getStatusCode());
...
+     $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response);
...
-    // @todo Remove the try/catch in favor of the two commented lines in
...
+    $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_id: This value should not be null.\n", $response);
...
-    // @todo Uncomment, remove next 2 lines in https://www.drupal.org/node/2820364.
-    $this->assertSame(500, $response->getStatusCode());
...
+    $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nfield_name: This value should not be null.\n", $response);

🎉🎉🎉🎉🎉🎉🎉🎉🎉 AWESOME!!!!!!!!!

amateescu’s picture

Status: Reviewed & tested by the community » Needs work

makes entity_type and field_name regular-required, which doesn't require an update path as it has no effect on storage

The "storage required" setting also doesn't have any effect on the storage yet! But that will change in #2841291: Fix NOT NULL handling in the entity storage and 'primary key' changes when updating the storage definition of an identifier field, and committing this patch without the corresponding not null additions to \Drupal\comment\CommentStorageSchema::getSharedTableFieldSchema() (and the upgrade path for them) is just kicking the problem down the road and introduces an inconsistency between the field storage definitions and the SQL storage column definitions, which is something I don't really agree with :/

amateescu’s picture

Title: 'entity_type' base field on Comment is required » The 'entity_type' and 'field_name' base fields on Comment are required
Status: Needs work » Needs review
StatusFileSize
new9.09 KB
new9.19 KB
new4.58 KB

Here's a complete fix, basically a combined version of the patch from #18 with an improved version of #15.

Since this is a bug fix and it's supposed to land in both 8.6.x and 8.7.x, separate patches are required because of #2949964: Add an EntityOwnerTrait to standardize the base field needed by EntityOwnerInterface.

The last submitted patch, 22: 2885809-22-8.7.x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 22: 2885809-22-8.6.x.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new13.73 KB
new13.83 KB
new4.64 KB

Now that the field_name column is actually required at the database level, some kernel tests need to be updated because they weren't adding comments properly.

wim leers’s picture

Added to #3002188: REST: top priorities for Drupal 8.7.x.

Also: so it's probably @amateescu who told me to make storage required — he just explained why :) Thanks, @amateescu!

I LOVE LOVE LOVE #25 — it shows that this was a widespread problem, and it fixes it everywhere, excellent!

longwave’s picture

+++ b/core/modules/comment/tests/src/Functional/Update/CommentUpdateTest.php
@@ -73,6 +73,34 @@ public function testPublishedEntityKey() {
+    if ($database->driver() === 'mysql') {
+      $table_description = $database
+        ->query('DESCRIBE {comment_field_data}')
+        ->fetchAllAssoc('Field');

I don't think we use this technique anywhere else, is this guaranteed to be stable across MySQL versions?

Could we try inserting NULL, and check that it succeeds before the update and fails afterwards?

amateescu’s picture

The test failures from #22 and the fixes required for them in #25 prove exactly that, so we could remove the update path test if it's deemed too icky because it's only testing the behavior in MySQL.

wim leers’s picture

Assigned: Unassigned » berdir

AFAICT this only needs a +1 from Berdir to become RTBC.

berdir’s picture

+++ b/core/modules/comment/src/CommentStorageSchema.php
@@ -60,6 +60,13 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st
 
+        case 'entity_type':
+        case 'field_name':
+          // The 'entity_type' and 'field_name' are required so they also need
+          // to be marked as NOT NULL.
+          $schema['fields'][$field_name]['not null'] = TRUE;
+          break;

this doesn't check that the field is actually set to required, so I think any storage update on that entity type/field is going to trigger the update already, e.g. comment_update_8301(), not just the one we think that does. Not 100% sure, but I wouldn't be surprised if the update path tests passes *without* the new update function :)

I'm always a bit worried about not null storage changes, I kind of expect that there are sites out there that have a messed up database where this update would then fail for them. That's the advantage of just making it required for the validation :)

amateescu’s picture

StatusFileSize
new14.4 KB
new14.35 KB
new1.26 KB

Discussed a bit with @Berdir and settled on fixing the first paragraph from #30 by doing a 'is storage required' check on those two fields.

As for the second paragraph of #30, no site can get into the situation of having NULL values for those columns in the comment tables thanks to the comment_entity_statistics table schema, which defines its own entity_type and field_name columns as NOT NULL, and that table is updated on each comment save in \Drupal\comment\Entity\Comment::postSave(). If we would have NULL values for any of those two columns, the transaction from \Drupal\Core\Entity\Sql\SqlContentEntityStorage::save would fail :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Right, and that logic is actually why REST integration was also exploding as our test coverage showed.

Perfect, thanks!

wim leers’s picture

🎉

BELGIAN CHOCOLATES FOR AMATEESCU AND BERDIR!

catch’s picture

Status: Reviewed & tested by the community » Needs work

So agreed with the patch, but I think this should be 8.7.x-only, which means we need an 87**() update function.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new14.31 KB
new4.29 KB

Okay :)

andypost’s picture

Rtbc++

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: 2885809-35.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

That was a random failure.

  • catch committed 876c6c1 on 8.7.x
    Issue #2885809 by amateescu, Wim Leers, dawehner, Berdir, andypost: The...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 876c6c1 and pushed to 8.7.x. Thanks!

wim leers’s picture

Priority: Normal » Major

Actually, this was the most important part of #2820364: Entity + Field + Property validation constraints are processed in the incorrect order, which was Major. So instead, marking this Major, instead of #2820364.

Status: Fixed » Closed (fixed)

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

dropa’s picture

I already made new issue about the problem https://www.drupal.org/project/drupal/issues/3052147

This update hook fails on comments that has no value submitted for field_name

sam152’s picture

Retroactively added a stub change record for this issue to reference from a hook_requirements patch: https://www.drupal.org/node/3053046.

maria.dis’s picture

The question is why drupal comments have a title. In no comment service, such as Facebook, or those used in newspapers have a title. I have disabled it to make the comment service more efficient. It occupies space and does not result in anything. The solution: do not update or use external comment services.

berdir’s picture

You can add a hook_comment_presave() and add something into the subject field, like the first few characters of the text.

There are open issues I think to make it optional, this merely enforced what was already expected.