Skip to content

Commit 3c4654d

Browse files
CIVIPLMMSR-709: Guard against NULL base table in Api4SelectQuery::autoJoinFK
Included in CiviCRM 6.18 PR: civicrm#36216
1 parent 1534390 commit 3c4654d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Civi/Api4/Query/Api4SelectQuery.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,19 @@ protected function autoJoinFK($key) {
817817
$joinTreeNode =& $this->joinTree[$baseTableAlias];
818818

819819
$useBridgeTable = FALSE;
820+
$baseTable = $explicitJoin['table'] ?? $this->getFrom();
821+
// The base table may not resolve to a string - e.g. getFrom() returns
822+
// NULL when the entity's table mapping is not available yet.
823+
// Joiner::getPath() is typed `string $baseTable`, so passing NULL would
824+
// throw an uncaught \TypeError rather than the \CRM_Core_Exception handled
825+
// below. Since the select clause silently ignores unknown fields (see the
826+
// fallback in the catch block), this function should not throw - bail out
827+
// gracefully instead of fataling.
828+
if (!is_string($baseTable)) {
829+
return;
830+
}
820831
try {
821-
$joinPath = $joiner->getPath($explicitJoin['table'] ?? $this->getFrom(), $pathArray);
832+
$joinPath = $joiner->getPath($baseTable, $pathArray);
822833
}
823834
catch (\CRM_Core_Exception $e) {
824835
if (!empty($explicitJoin['bridge'])) {

0 commit comments

Comments
 (0)