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.
As some selection views are quite expensive in terrms of execution time, it seems a natural solution to cache (e.g. by time).
This has caused issues here. How to reproduce:
* Create an entityreference field with a selection view on a node
* Set a (say) 1-hour time cache on the view
* Edit one node and submit => no problem
* Edit another node with another entityreference target value and submit => Validation error: "The referenced entity (...) is invalid."
Debugging this in entityreference_field_validate() shows that $valid_ids has the target value of the first edit.
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedI have encountered exactly the same problem. With caching, 'The referenced entity (...) is invalid', without caching, no problem.
Comment #2
selwynpolit CreditAttribution: selwynpolit commentedditto. I guess other folks haven't found this to be a big issue so I'm turning off caching on those views for now.
Comment #3
bjcooper CreditAttribution: bjcooper commentedJust chiming in to say that I've run into this exact same issue. In my case, caching the View would provide a significant performance increase, so having to turn off caching for the Entity Reference views is slightly more than irritating.
I haven't looked more into it, but here's the description of my situation and my impression of what's going on:
My Setup
How to Make Bad Stuff Happen
Why I Think Bad Stuff Happens
Comment #4
geek-merlinI did not investigate this further, but i remember there are some views issues about "caching does not respect arguments" or so.
Guess this might do the trick.
Comment #5
MustangGB CreditAttribution: MustangGB commentedIs still still something that needs fixing?
Comment #6
spelcheck CreditAttribution: spelcheck commented@MustangGB, yes please keep this open. Though it's possible this will end up being issue with entityreference_filter.
I'm also using entityreference_filter with entityreference. I've only started to diagnose the issue, but so far when using a entityreference_filter view for my entityreference fields, I'm seeing the same issue as in #3. If the filtering view has *any* caching, entityreference_field_validate() $valid_ids appears to populate with $ids from the entityreference field that was processed immediately before it. It is looking to be intermittent, so I'll put time into properly diagnosing it.
Meantime #2 is a workaround, albeit a performance hit.