Skip to content

Defensive coding on Query::getQueryStorageMap() - #4669

Open
paul-m wants to merge 4 commits into
4.xfrom
defensive-query
Open

Defensive coding on Query::getQueryStorageMap()#4669
paul-m wants to merge 4 commits into
4.xfrom
defensive-query

Conversation

@paul-m

@paul-m paul-m commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Fixes [issue#]

Describe your changes

getQueryStorageMap() looks like this:

  public function getQueryStorageMap(DatastoreQuery $datastoreQuery) {
    $storageMap = [];
    foreach ($datastoreQuery->{"$.resources"} as $resource) {
      [$identifier, $version] = DataResource::getIdentifierAndVersion($resource["id"]);
      $storage = $this->datastore->getStorage($identifier, $version);
      $storageMap[$resource["alias"]] = $storage;
    }
    return $storageMap;
  }

Since the evalution of $datastoreQuery->{"$.resources"} can return NULL if metastore nodes are present but datastore tables are not, as when a developer grabs a database from production, this results in a TypeError rather than returning an empty storage map.

We fix this with a NULL-coalesce to allow the foreach() to process an empty array instead of erroring out on NULL.

QA Steps

  • Add manual QA steps in checklist format for a reviewer to perform. Be as specific as possible, provide examples if appropriate.

Checklist before requesting review

If any of these are left unchecked, please provide an explanation

  • I have updated or added tests to cover my code
  • I have updated or added documentation

@paul-m
paul-m changed the base branch from 2.x to 4.x August 26, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant