Skip to content

Defensive coding on Query::getQueryStorageMap()#4669

Open
paul-m wants to merge 1 commit into2.xfrom
defensive-query
Open

Defensive coding on Query::getQueryStorageMap()#4669
paul-m wants to merge 1 commit into2.xfrom
defensive-query

Conversation

@paul-m
Copy link
Contributor

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

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

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