Problem/Motivation

For DX ContentEntityDatabaseStorage provides defaults for the base and data table if it is not specified. Actually doing this, however, i.e. specifying an entity type as translatable but not specifying a data table leads to a fatal error upon module installation.

The problem is that, due to the default value inside of ContentEntityDatabaseStorage $this->getDataTable() returns something different (i.e. the default value) than $this->entitytype->getDataTable() (which returns an empty string).

When building the schema, the schema handler asks the storage whether there is a data table when initializing the tables but when building the actual table mapping the storage asks the entity type directly. Therefore the resulting schema has the scaffolding for a data table, but the fields key is empty. Thus an SQL exception is thrown as a table is trying to be created without any fields/columns.

Proposed resolution

Replace $this->entityType->getDataTable() with $this->getDataTable() in ContentEntityDatabaseStorage::getTableMapping().

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Status: Active » Needs review
FileSize
1.01 KB
892 bytes

Just for fun including a patch to see whether the data table check is still need at all. The second patch should be green and is the actual bugfix here.

We should also provide a test for this.

Status: Needs review » Needs work

The last submitted patch, 1: 2328565-1-ceds.patch, failed testing.

The last submitted patch, 1: 2328565-1-ceds-lets-see.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
2.17 KB
3.18 KB

Yeah, I had the slight suspicion that this was no longer needed.

Still needs tests, though me thinks.

tstoeckler’s picture

FileSize
7.86 KB
11.04 KB

Here's a test for this behavior. Instead of testing that the table names can be omitted, I added a test that the defaults can be overridden. The amount of coverage is the same but we want to move away from specifying the table names everywhere so this is the more modern approach. The test tests all four table types, so provides more coverage than just for this bug, but that shouldn't hurt.

I uploaded the interdiff as the "fail" patch as only a very small non-test fix is contained there, so that should work.

If this is red/green as expected I think it is RTBC material.

The last submitted patch, 5: 2328565-5-ceds-fail.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: 2328565-5-ceds-pass.patch, failed testing.

tstoeckler’s picture

Title: Omitting the "data_table" for translatable entity types is broken » Omitting the "base_table" or "data_table" for entity types is broken
Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.5 KB
12.76 KB

Ahh, I had feared that this would uncover more issues.

Status: Needs review » Needs work

The last submitted patch, 8: 2328565-8-ceds.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kristiaanvandeneynde’s picture

I just ran into this as well.

I think the right approach here would be to make sure that both $this->entitytype->getDataTable() and $this->getDataTable() return the same result. Trying to replace calls with their counterpart just seems like we will still have places where this may bug out.

Seeing as core relies on the data table being BASETABLE_field_data all over the place, why not have EntityType make sure it has the right defaults set when the keys are omitted and read those values in the storage handler instead of figuring out the defaults there (and in views)?

kristiaanvandeneynde’s picture

Or, alternatively, seeing as getBaseTable(), getDataTable(), etc. all mention they are only used in the SQL storage: Why don't we have all the logic in the SQL storage and let the EntityType do something like this?

function getBaseTable() {
  $storage = $entity_type_manager->getStorage($this->id);
  if ($storage instanceof SqlContentEntityStorage) {
    return $storage->getBaseTable();
  }
}
tstoeckler’s picture

Re #11: As you mention in #12 the idea was that at some point (i.e. 9.x) we could remove EntityType::getBaseTable() so that's why we moved more calls to the storage directly. I'm not sure if I still agree with that, but that was the idea at the time.

You idea in #12 actually sounds fairly awesome in principle, but I'm not sure how we would get the $entity_type_manager from within an entity type. We could say, that this is code that's going to me dropped in 9.x anyway, and we don't care about elegance and slam a \Drupal::service('entity_type.manager') in there, but (even though I would be fine with that) I don't think that's going to fly.

kristiaanvandeneynde’s picture

Looking at EntityType::getBundleConfigDependency(), core seems to be fine with using \Drupal in there.

tstoeckler’s picture

Wow, that's true. Well I guess why not, then?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

bradjones1’s picture

Version: 8.5.x-dev » 8.6.x-dev
amateescu’s picture

I wonder how was the patch from #8 generated on September 3 when (partly) the same fix was committed on August 18: #2322097: Enforce data tables for translatable entity types in the SQL entity storage.

Does that mean that this is no longer a problem and we can close it?

tstoeckler’s picture

A) The other fix was in a different place in the same file. So while it won't apply anymore, it did at the time.
B) No, I think it's still needed. SqlContentEntityStorage still pretends to hold it's own reference to the table names independent of the entity type. So we should fix those instances where we are still introspecting the entity type directly. Of course, the whole premise of this might change now with #2232465: Deprecate table names from entity definitions or some of the other related issues, but I don't think we can just close it.

amateescu’s picture

Oh, I didn't realize that the fix was in a different place, sorry :) And I agree that we should see how #2232465: Deprecate table names from entity definitions pans out before doing anything here.

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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.