Bugfix Issue 1567 ExecTree EB Alias 1066 - sebiboga/testlink-upgraded GitHub Wiki
Bugfix — Issue 1567 — SQL 1066 "Not unique table/alias 'EB'" in exec tree when a combined bug+platform filter matches nothing
Issue: #1567
Branch: fix/issue-1567-eb-alias-collision
Status: FIXED & VERIFIED (2026-09-22)
Symptom
Running the execution-navigator tree through the modern BFF with a linked-bug
filter whose bug id has no matching execution_bugs row produces the MySQL error
ERROR 1066 (42000) at line 1: Not unique table/alias: 'EB'
Measured pre-fix (fresh DB, fixture tmp/fixtures_1562.php, admin/admin,
tproject_id=1, testplan_id=2, build_open=1, platform_id=1):
GET /api/execnavigator/index.php?action=init&tplan_id=2&tproject_id=1&filter_bugs=X-1&setting_platform=999&setting_testplan=2→ responded[200]with the legacy DB Access Error debug page (not JSON);eventstable got twoDATABASErows (log_level=1):1066 - Not unique table/alias: 'EB' - /* Class:testplan - Method: getLinkedForExecTree sqlUnion - executions */ SELECT … JOIN execution_bugs EB ON EB.execution_id = E.id … JOIN execution_bugs EB ON EB.execution_id = E.id … AND EB.bug_id IN ('X-1');- standalone SQL harness: same query piped to
mysql→ERROR 1066 (42000).
Severity Low (crafted filter_bugs input only; the modernized screen exposes no
bugs filter input), as reported.
Root cause chain
helper_bugs_sql()—lib/functions/testplan.class.php:1087-1106— builds the bug filter join asJOIN execution_bugs EB ON EB.execution_id = E.idwith the alias hardcoded toEB(:1103) and stores it as$my['join']['bugs'](assigned at:6526-6527).getLinkedForExecTree()(lib/functions/testplan.class.php:6166) emits$my['join']['bugs']in the exec branch at two positions::6277— in the first join block (beforeLEBBPand beforeJOIN executions E) — spurious;:6293— afterJOIN executions E, annotated// need to be here because uses join with E table alias— intended.
- When
bug_idis set,$my['join']['bugs']is non-empty at BOTH positions → duplicate aliasEBin a single query → MySQL 1066 (execTree()→fetchRowsIntoMap(),lib/functions/execTreeMenu.inc.php:146). - The
not_runUNION branch is NOT part of the collision: it is nulled wheneverbug_idis set (:6211/:6215, return:6298). This corrects the report's original "UNION branch" hypothesis — see the issue comment trail.
Regression source
Upstream commit ff21e99201 (2020-04-04, "new class build.class.php" big
testplan.class.php refactor) ADDED the spurious pre-LEBBP bugs join at :6277.
The pre-refactor function emits the bugs join only once, at the post-E position
(git show ff21e99201^:lib/functions/testplan.class.php).
Blast radius
join['bugs']occurrences::6237(not_run branch — harmless),:6277(BUG),:6293(intended).getLinkedForExecTreeCross/getLinkedForExecTreeIVUdo not emit it.- Consumers:
execTree()←tlTestCaseFilterControl::build_tree_menu()(execution_mode) ← BFFapi/execnavigator/index.phpand legacylib/execute/execNavigator.php.
Fix (minimal)
Removed the spurious duplicate from the exec branch:
lib/functions/testplan.class.php
- $my['join']['bugs'] . (pre-LEBBP block, :6277)
The intended post-E bugs join (:6293) is kept, so bug-filter semantics are
unchanged (this also removes a latent forward-reference of E.id). No other
files touched. Alternatives rejected: renaming the alias to EB2 (keeps a
redundant join) or keeping only the pre-LEBBP join (requires MySQL-only
forward reference).
Verification
- SQL unmatched (
X-1): exactly ONEJOIN execution_bugs EB …, executes cleanly, 0 rows. - SQL matching (
BUG-123): returns the executed TC (exec_status=p). - BFF end-to-end:
filter_bugs=X-1&setting_platform=999→200 {"status":"ok"}empty tree;filter_bugs=BUG-123&setting_platform=1→200 status:ok1 child; baseline unchanged. - Event Viewer:
eventsmax id unchanged after post-fix runs — no new Error/Warning rows. - Regression suite:
tmp/TLU_Test_Cases.md→Suite 1567— PASS.
Test matrix
| Case | Pre-fix | Post-fix |
|---|---|---|
bug_id unmatched (SQL) |
ERROR 1066 |
OK, 0 rows |
bug_id matching (SQL) |
— (never ran) | OK, returns TC |
| BFF bug+platform filter | DB Access Error + DATABASE 1066 events | 200 status:ok, empty tree |
| BFF no-filter baseline | OK | OK (unchanged) |
| Event Viewer | 1066 ERROR rows | no new rows |