When you install the locale module, the core string_translation service will receive locale's translator class, which has an indirect dependency on the database.
If you then try to serialize anything, directly or indirectly, which:
a) uses StringTranslationTrait; and
b) does not use DependencySerializationTrait;
...you may get a "database connection is not serializable" exception, if the consumer of StringTranslationTrait has a reference to the string_translation service, set either explicitly by setStringTranslation() or implicitly by getStringTranslation().
I'm marking this as a major issue because it seems to me that it is squarely an architectural conflict between DependencySerializationTrait and StringTranslationTrait, and may need to be resolved in several different places in core. However, the EntityType class, and its descendants, are maybe the most visible and pervasive manifestation of this problem, so this issue fixes the problem in EntityType.
Original issue report, filed against Lightning:
Add DependencySerializationTrait to EntityType class.
There are a couple of longer-term solutions which can be discussed and worked on in other issues:
Without this patch, that condition could happen essentially by accident if you, or anything you are referencing (explicitly or implicitly) uses StringTranslationTrait without DependencySerializationTrait. With this patch, the only way you will encounter the serialization exception is if you (or a parent class you are extending) have explicitly injected the service. Which means you are in a position to actually fix the problem, either by removing the reference to the service, or by importing DependencySerializationTrait.
Commit the patch.
None.
None.
None.
Fixed
8.6 β°οΈ
Last updated
Enhances developer experience.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.