Fix project typeahead query with columns when string is not name prefix

Summary:
Avoid an AphrontParameterQueryException when running a typeahead project name query with `mustHaveColumns` when the search string is not the `prefix` of the project name.
Since rP9a1d59ad5bd51ef4bf56533db260cc9e11a54fe6, Phorge runs queries in two phases: First `prefix`, then `content`, to sort project results accordingly.

`PhabricatorTypeaheadDatasource::loadResultsForPhase()` first goes for the `prefix` phase. This query may return zero results.
Current code does not correctly handle this situation.
Thus make the code smoothly skip to the `content` query phase and not run a `PhabricatorProjectColumnQuery` with an empty project PHID array parameter to end up in an exception.

Closes T16068

Test Plan:
* Have a parent project named `Foo` with a milestone named `Sprint Chocolate Cake`
* Create a project workboard for that milestone named `Sprint Chocolate Cake`
* In a project with no workboard yet, select "Import Columns" to end up on http://phorge.localhost/project/board/1/import/
* See that typing the second string token (`Chocolate`) shows no autocomplete project proposals
* Click the Magnifier button to `Browse Projects`
* Start typing `Chocolate` and get an AphrontParameterQueryException
* Apply the patch
* See that typing the second string token (`Chocolate`) now shows autocomplete project proposals
* Click the Magnifier button to `Browse Projects`
* Start typing `Chocolate` and get project search results

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16068

Differential Revision: https://we.phorge.it/D26030
This commit is contained in:
Andre Klapper 2025-05-22 12:08:30 +02:00
parent 93d9e1b05d
commit 87da4d2a33

View file

@ -51,7 +51,7 @@ final class PhabricatorProjectDatasource
$projs = mpull($projs, null, 'getPHID');
$must_have_cols = $this->getParameter('mustHaveColumns', false);
if ($must_have_cols) {
if ($must_have_cols && $projs) {
$columns = id(new PhabricatorProjectColumnQuery())
->setViewer($viewer)
->withProjectPHIDs(array_keys($projs))