- 🇬🇧United Kingdom nlisgo
I can recreate the issue in 11.x.
drush ev "\Drupal::entityTypeManager()->getStorage('node')->create(['title' => 'test', 'type' => 'article', 'uid' => 12345])->save();"
SELECT * FROM node_field_data; +-----+-----+---------+----------+--------+-----+-------+------------+------------+---------+--------+------------------+-------------------------------+ | nid | vid | type | langcode | status | uid | title | created | changed | promote | sticky | default_langcode | revision_translation_affected | +-----+-----+---------+----------+--------+-----+-------+------------+------------+---------+--------+------------------+-------------------------------+ | 2 | 2 | article | en | 1 | 0 | test | 1719579473 | 1719579473 | 1 | 0 | 1 | 1 | +-----+-----+---------+----------+--------+-----+-------+------------+------------+---------+--------+------------------+-------------------------------+
- Status changed to Postponed: needs info
6 months ago 1:45pm 28 June 2024 - 🇬🇧United Kingdom nlisgo
Since we have focused in on the handling of setting a uid which doesn't correspond to a user on Node, I thought I would see how the same scenario is handled for comments.
drush ev "\Drupal::entityTypeManager()->getStorage('comment')->create(['entity_id' => 2, 'entity_type' => 'node', 'field_name' => 'comment', 'comment_type' => 'comment', 'uid' => 12345, 'comment_body' => ['value' => 'This is the comment body', 'format' => 'basic_html']])->save();"
The result of this is to store the uid is given:
SELECT * FROM comment_field_data; +-----+--------------+----------+--------+-------+------+-----------+---------+------+------+----------+----------+------------+------------+--------+-------------+------------+------------------+ | cid | comment_type | langcode | status | uid | pid | entity_id | subject | name | mail | homepage | hostname | created | changed | thread | entity_type | field_name | default_langcode | +-----+--------------+----------+--------+-------+------+-----------+---------+------+------+----------+----------+------------+------------+--------+-------------+------------+------------------+ | 1 | comment | en | 0 | 12345 | NULL | 2 | NULL | NULL | NULL | NULL | NULL | 1719581477 | 1719581477 | 01/ | node | comment | 1 | +-----+--------------+----------+--------+-------+------+-----------+---------+------+------+----------+----------+------------+------------+--------+-------------+------------+------------------+
It seems there is a desire to not allow the storing of nodes if a specified uid does not match a stored user. See #9. But, if this is expensive perhaps it is better to just allow the storing of the uid as provided. This could be achieved by removing the following:
From
\Drupal\node\Entity\Node::presave()
// If no owner has been set explicitly, make the anonymous user the owner. if (!$translation->getOwner()) { $translation->setOwnerId(0); }
Is there any appetite to just remove this code and not throw an exception at all?