Follow-up to #2403271: Return NULL on EntityRepository::loadEntityByUuid() when the UUID is invalid or it doesn't exist
Problem/Motivation
There is no unit test to verify the behavior of EntityStorageBase::load() or EntityStorageBase::loadMultiple().
Proposed resolution
Write some tests.
Remaining tasks
User interface changes
API changes
Beta phase evaluation
| Issue category | Task because we're writing tests to verify behavior that isn't wrong. |
|---|---|
| Issue priority | Normal because nothing is broken. |
| Unfrozen changes | Unfrozen because we're adding automated unit tests. |
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 2464041-27.patch | 5.36 KB | quietone |
| #27 | diff-17-27.txt | 1.01 KB | quietone |
| #17 | interdiff.txt | 2.21 KB | mile23 |
| #17 | 2464041_17.patch | 5.28 KB | mile23 |
| #13 | 2464041_13.patch | 5.2 KB | mile23 |
Comments
Comment #1
joshi.rohit100I think its Entity::load()/loadMultiple() ?
Comment #2
anksy commentedComment #3
shivanshuag commentedThe loadMuliple case a bit tricky. It takes an array of UUID's as an argument. Should it return NULL even if a single UUID is invalid or NULL in the return array for those UUID's that are invalid/non-existing?
In the case of invalid id's, EntityStorage::loadMultiple(), which is called by Entity::loadMultiple($ids), removes them from the result array, so I think there shouldn't be any need to make changes in loadMultiple() function.
Entity::load($id) makes use of EntityStorage::load() function, which calls EntityStorage::loadMultiple() with a single id in an array as the parameter. EntityStorage::load() returns null if EntityStorage::loadMultiple() returns an empty array, so I think there is no need to make changes in load() function too.
Comment #4
berdirId, not UUID.
Comment #5
berdirAlso, we should return NULL
Comment #6
m0zzy commentedHi all,
I'm in DrupalDevDays in Montpellier today (mentoring session)
And I'll try to fix this issue.
Comment #7
bhoquy commentedHi, I'm in drupal dev days and i'll try to fix this issue.
Comment #8
andrewsuth commentedIn the absence of m0zzy in the mentoring room, I investigated this issue and will post the results soon.
Comment #9
andrewsuth commentedI am unable to reproduce this issue.
Some quick debugging seems to show that there is no issue with
loadandloadMultiplewhile using their calling functions (entity_loadandentity_load_multiple) which returns their expected results:Loading a single entity
Results in:
Loading multiple entities
Results in:
Comment #10
manningpete commentedPostponed for more information and removed the novice tag.
Why: Per #9 issue couldn't be recreated; need more information. Removed novice tag since issue is not actionable by novice.
Novice tag documentation: https://www.drupal.org/core-mentoring/novice-tasks
Comment #11
andrewsuth commentedCan you provide inputs or unit tests which replicate this issue?
Comment #12
mile23@andrewsuth If it's at all possible, could you turn the experimentation in #9 into a runnable test?
That way we can be sure the behavior is correct.
Thanks.
Comment #13
mile23Updated issue summary to reflect that
EntityManager::load()/loadMultiple()doesn't exist any more, and is on the storage object.Rescoping a bit to concentrate on
EntityStorageBase.Since
EntityStorageInterface::load()accepts an ID ofmixedtype, there's no such thing as an invalid parameter to it, or toloadMultiple(), since it accepts an array of the same type. Whether a given ID is of an illegal type would be determined bydoLoadMultiple()in the concrete storage class, rather thanEntityStorageBase, which is abstract. In such a case,doLoadMultiple()should simply ignore the illegal ID.This patch contains a test class to cover
EntityStorageBase.It
@covers ::loadand::loadMultiple.For
load():For
loadMultiple():Note that we're only testing the behavior of
loadMultiple()for entity types without static caching.Comment #14
mile23Still applies, still passes.
Comment #15
mile23Comment #17
mile23Removed @file per new CS, added keys to data provider arrays for readability.
Comment #27
quietone commentedChanging to a task,
I have also rerolled the patch for 10.0.x
Comment #28
lendudeDiscussed briefly with @quiteone in #bugsmash about the added value here and it was pointed out that this still checks for logic errors even if the expected value is basically the same as whatever we pass as the return value for doLoadMultiple.
So, more test coverage ++
Comment #29
alexpottCommitted and pushed 50ddf37fda to 10.1.x and 9909596e5e to 10.0.x and 112de03974 to 9.5.x and 38e9b318a3 to 9.4.x. Thanks!
Backported to 9.4.x to keep test aligned. I ran the test on 9.4.x / php 7.3 locally.