Comments

jibran created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
StatusFileSize
new4.08 KB

Here is the basic test for start. It passes on both 8.x-1.x and 8.x-2.x.

jibran’s picture

Category: Task » Bug report
Priority: Normal » Major
StatusFileSize
new6.62 KB
new4.9 KB
new9.05 KB
  • Added a failing test
  • Fixed the bug by adding the triggers on revision tables.
  • Update path fix can go to follow up with tests.

The last submitted patch, 3: add_tests_for-2772611-3-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: add_tests_for-2772611-3.patch, failed testing.

jibran’s picture

Title: Add tests for revisionable entities » target_id_int column doesn't exist for field revision tables
Status: Needs work » Needs review
StatusFileSize
new853 bytes
new9.05 KB

Fixed the stupid copy paste error.

jibran’s picture

Minor observation.

  1. +++ b/src/EventSubscriber/FieldStorageSubscriber.php
    @@ -137,6 +139,9 @@ class FieldStorageSubscriber implements EventSubscriberInterface {
    +        if ($entity_type->isRevisionable() && ($table = $mapping->getDedicatedRevisionTableName($field_storage_definition))) {
    

    Field Revision table is always a dedicated table if an entity is revisionable.

  2. +++ b/src/EventSubscriber/FieldStorageSubscriber.php
    @@ -137,6 +139,9 @@ class FieldStorageSubscriber implements EventSubscriberInterface {
    +          $tables[$table][] = $column;
    

    column name is same across the tables.

jibran’s picture

Added #2773099: Add tests for base fields of revisonable entity as a follow up. After that we can work on upgrade path test for base fields of revisonable entity.

jibran’s picture

StatusFileSize
new726 bytes
new9.06 KB

$field_storage_definition can be NULL so changed the variable.

Status: Needs review » Needs work

The last submitted patch, 9: target_id_int_column-2772611-9.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
jibran’s picture

Title: target_id_int column doesn't exist for field revision tables » target_id_int column doesn't exist for revision tables

Current patch is only fixing the bug: "target_id_int column doesn't exist for entity revision field tables."

jibran’s picture

Title: target_id_int column doesn't exist for revision tables » target_id_int column doesn't exist for field revision table
StatusFileSize
new1.77 KB
new9.15 KB

field revision table only exist if both entity and field storage are revisionable.

chx’s picture

        if ($entity_type->isRevisionable() && $field_storage_definition->isRevisionable()) {
          $revision_table = $table_mapping->getDedicatedRevisionTableName($field_storage_definition);

yes, we only need to deal with some revision table if both definitions are revisionable. However, the field will only live in a dedicated table if its cardinality is not 1. If its cardinality is 1 then it might live in the shared revision data table (if the entity is translatable) or the just revision table (if the entity is not translatable) but it's enough to just rely on the table name being non-empty as SqlContentEntityStorageSchema::getEntitySchemaTables does. So:

        if ($entity_type->isRevisionable() && $field_storage_definition->isRevisionable()) {
          if ($table_mapping->requiresDedicatedTableStorage($field_storage_definition)) {
            $revision_table = $table_mapping->getDedicatedRevisionTableName($field_storage_definition)
          }
          if ($table_mapping->allowsSharedTableStorage($field_storage_definition)) {
            $revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable();
          }
jibran’s picture

StatusFileSize
new2.2 KB
new9.8 KB

Thanks for the explanation. Here is the new patch

chx’s picture

Status: Needs review » Reviewed & tested by the community

So... I have read the patch and of course it looks great! Then I began wondering, does the system even put the revision data into the keyvalue? I mean, it could skip it, the revision and the base column schema are obviously the same.

So I opened the database and select * from key_value where name like 'node.field_schema_data.changed'; and yes, node_field_revision is there. While theoretically we could just use this data in the update handler, we couldn't do so in FieldStorageSubscriber because as are painfully aware it might happen that one gets called before the database actually contains the field columns.

  • jibran committed 83d32ff on 8.x-2.x
    Issue #2772611 by jibran, chx: target_id_int column doesn't exist for...
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! committed and pushed to 8.x-2.x

jibran’s picture

+++ b/dynamic_entity_reference.install
@@ -64,12 +65,28 @@ function dynamic_entity_reference_update_8001() {
+        $revision_table = NULL;
+        if ($entity_type->isRevisionable() && $field_storage_definition->isRevisionable()) {
+          if ($table_mapping->requiresDedicatedTableStorage($field_storage_definition)) {
+            $revision_table = $table_mapping->getDedicatedRevisionTableName($field_storage_definition);
+          }
+          elseif ($table_mapping->allowsSharedTableStorage($field_storage_definition)) {
+            $revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable();
+          }
+          $schema->changeField($revision_table, $column, $column, $spec);
+          $schema->changeField($revision_table, $type_column, $type_column, $type_spec);
+        }
...
+          if ($revision_table) {
+            $field_schema_data[$revision_table]['fields'][$column] = $spec;
+            $field_schema_data[$revision_table]['fields'][$type_column] = $type_spec;
+            $entity_storage_schema_sql->set($key, $field_schema_data);
+          }

Just for the record the upgrade path test for this change is still pending.

Status: Fixed » Closed (fixed)

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