Problem/Motivation
During a configuration import, the Entity system performs validation to ensure that bundles are not deleted if they are in use on the target site. The current code for this validation assumes that the storage for all validated bundles will return a usable query via the getQuery() method. However, this is not the case for bundles using ContentEntityNullStorage (which appears to be used by contact forms). Such bundles will cause a QueryException to be thrown, breaking the import process.
Proposed resolution
Take advantage of the fact that most bundles (seemingly all those currently defined in core) use a storage mechanism that supports the hasData() method (as specified by the DynamicallyFieldableEntityStorageInterface interface). When checking for existing entities for a given bundle, use hasData() if supported by the bundle's storage mechanism. If not, only then fall back to the current approach and attempt to build and execute an entity query.
Remaining tasks
- Discuss alternate solutions and related issues
- Determine whether this issue will be obviated by other ongoing work
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#1 | 2409013-1.patch | 2.56 KB | ndewhurst |
Comments
Comment #1
ndewhurstComment #2
ndewhurstComment #3
ndewhurstComment #4
ndewhurstComment #5
chx CreditAttribution: chx commentedWhy? Why don't we make hasData mandatory and add it to null storage? And it can return FALSE. It would be simpler, no?
Comment #6
ndewhurstchx, that would be awesome. I confined my changes to this one spot simply because I wasn't well versed in the broader discussions/history surrounding storage. (a.k.a. I was being timid ;)
Comment #7
alexpottComment #8
alexpottSince #2335879: Change SqlContentEntityStorageSchema::requiresEntityDataMigration() to ask the old storage handler if it has data rather than assuming yes unless NULL storage ContentEntityNullStorage::hasData() exists.
Comment #9
alexpottClosing as a duplicate of #2337753: ContentEntityNullStorage does not implement a query service which now has a test for this specific issue.
Comment #10
ndewhurstThanks Alex - that makes sense. Just for my own understanding, does this mean another storage could come along that doesn't provide a query mechanism (and our expectation that there will always be one becomes a matter of convention)? Not that that would be a problem, especially in a controlled system. I'm mostly just trying to refresh my memory on this stuff without an active D8 site in front of me :)
I'll keep an eye on that other issue...