Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The RelationLinkManager::writeCache() is caching the entity_type in the relation link.
Proposed resolution
Cache the entity type id instead.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#18 | hal_relationlinkmanager-2868362-18-interdiff.txt | 4.18 KB | Berdir |
#18 | hal_relationlinkmanager-2868362-18.patch | 5.69 KB | Berdir |
#12 | hal_relationlinkmanager-2868362-12.patch | 2.92 KB | Ginovski |
#12 | interdiff-2868362-10-12.txt | 1.4 KB | Ginovski |
Comments
Comment #2
Ginovski CreditAttribution: Ginovski at MD Systems GmbH commentedChanged to id.
Tests needed.
Comment #3
BerdirAlso related, this one has the same problem as TypeLinkManager used to have: #2567133: getTypes in TypeLinkManager doesn't work with the null cache back end
This changes the return value, but I can't imagine that anyone relies on this, and based on what I found, we only seem to care about field names?
Our installer actually broke in 8.3 somehow because we have entity type objects with "loaded" StringTranslation objects (that's my guess at least) that then get serialized including their service and then it explodes with a cannot serialize container exception.
Comment #4
dawehnerI wonder whether this actually could cause some fatals, which might be a reason for this to be critical.
Here is some fun code:
Durpal, the only system which writes to the cache, and then reads from it before its doing anything else.
Here is some test coverage for this issue.
Comment #6
BerdirWe had a fatal in our install profile, starting with 8.3, not sure what makes the difference, not sure about critical though.
But yeah, all this is very Durpal indeed.
Comment #7
dawehnerNote: #4 is a test only patch ... feel free to take it.
Comment #8
Wim LeersThis code has not been changed in eons, why is this causing problems *now* all of a sudden?
Comment #9
Wim LeersIOW: why is this major? Why is this not normal or even minor? How can this cause problems? What are the STR to even cause problems?
Comment #10
Berdir#4 has tests (Thanks @dawehner!), we just need to merge it together.
It's IMHO major because it can result in serialization exceptions under some cases, see #3. In our case it is during installation, called by default_content. Hard to reproduce, not sure why it only happened for us and only since 8.3, but it does and when it does then there is no workaround.
Just combined the two patches together.
Comment #11
Wim LeersAutomatic IDE changes? I think we want to revert these.
Then this is RTBC.
Comment #12
Ginovski CreditAttribution: Ginovski at MD Systems GmbH commentedAddressed #11.
Comment #13
Wim LeersThanks @Ginovski!
Comment #15
andypostUnrelared
Comment #16
alexpottThis results in an API change :(
Something somewhere could be relying on \Drupal\hal\LinkManager\RelationLinkManagerInterface::getRelationInternalIds() actually returning an entity type object.
I think we have to care about BC here.
Maybe we should cache the ID but on get load the entity type to preserve the API. But also add an
entity_type_id
key to the array and deprecateentity_type
.Sorry. BC is hard.
Comment #17
BerdirHm. The documentation fairly clearly states that it returns ids:
I think it's more likely that someone runs into errors because they use it as documented. But fine, I'll think of something, will require rewriting some of that code, will also improve it so the caching isn't so weird.
Also, core only seems to ever use the field names from this method, which is why nobody notices this I guess.
Comment #18
BerdirCame up with the idea of adding entity_type_id and only then noticed that @alexpott suggested exactly that. I guess that's the only option that makes sense when keeping BC.
Not sure how to document that a single key of the return value of a method is deprecated.
Also not sure about 8.3, but this is a bug that is causing fatal errors for us in our installer, as mentioned, I'm not 100% clear why exactly.
Comment #19
dawehnerIt is a bit sad that this patch now fixes two things at the same time (the return value and the caching problem), but I guess this is how it is.
Comment #20
alexpottCommitted 4ad11bc and pushed to 8.4.x. Thanks!
I credited @dawehner, @Wim Leers and myself for review comments.
I think this should be backported to 8.3.x but I'm going to ask other committers first.
80 chars - fixed on commit.
Spacing - fixed on commit.
Comment #22
BerdirI just had the same error on another install profile, when trying to install in german.
The patch in #18 seems to have been tested against 8.3.x, so setting back to RTBC as the patch applies there as well.
Thanks for the coding standard fixes, I was apparently a bit lazy. Might make sense to cherry-pick the commit then :)
Comment #23
alexpottIn discussion with @xjm about backporting the patch @xjm pointed out that the docs weren't clear about how this change was not a significant API break. I've tried to fix this on #2877593: Improve \Drupal\hal\LinkManager\RelationLinkManager::getRelations() documentation
Comment #25
alexpottSo given that storing entity types in the cache is resulting in failed installs I've backported this fix to 8.3.x
Comment #27
quietone CreditAttribution: quietone at PreviousNext commentedpublish the change record