Don't persist failed search terms (#5039)

If a column is defined as searchable, that is not actually searchable (like a partial) and a user filters a list using the searchbox, an Exception is thrown.

Unfortunately, this errorenous search term has already been persisted to the session so on subsequent page loads, the user is presented with an Exception with no way to resolve it themselves.

This PR catches any exception that happens during the search and resets any persisted search terms so that the user can continue working after a page load.

The exception itself will still be thrown.

To reproduce the issue this PR solves:

Set a partial column in any list as searchable: true
Submit a search query
Hit F5
This commit is contained in:
Tobias Kündig 2020-04-27 09:55:40 +02:00 committed by GitHub
parent a2b835864e
commit dc72cafcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -128,7 +128,14 @@ class Search extends WidgetBase
* Trigger class event, merge results as viewable array
*/
$params = func_get_args();
$result = $this->fireEvent('search.submit', [$params]);
try {
$result = $this->fireEvent('search.submit', [$params]);
} catch (\Throwable $e) {
// Remove the search term from the session if the search has failed.
$this->setActiveTerm('');
throw $e;
}
if ($result && is_array($result)) {
return call_user_func_array('array_merge', $result);
}