When using the Link field search or calling the /api/method/frappe.desk.search.search_link API, the request fails with a PostgreSQL error if the searched DocType does not have “Translate Link Fields” enabled.
The error occurs when the search text is a comma (,) or certain special characters.
Instead of returning an empty result, the API fails with a database-level function error.
Context information (for bug reports)
Output of bench version
frappe 14.99.3
Database: PostgreSQL
Frappe install method: Bench (developer setup)
Steps to reproduce the issue
-
Open any Link field pointing to a DocType that does not have Translate Link Fields enabled.
-
Type a comma
,in the search box. -
Or call the API directly:
{ "txt": ",", "doctype": "AnyDoctypeWithoutTranslation", "ignore_user_permissions": 0, "reference_doctype": "AnyReferenceDoctype" }
Observed result
The request fails with a PostgreSQL error similar to:
psycopg2.errors.UndefinedFunction: function strpos(unknown) does not exist
LINE 1: ... (1 / nullif(strpos(', ...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
This occurs because the system attempts to perform a relevance check using a string literal that PostgreSQL cannot interpret correctly.
Expected result
-
The Link field search should handle commas and other special characters safely.
-
The query should not fail, regardless of whether “Translate Link Fields” is enabled or not.
-
The API should return zero or valid results instead of a database exception.
Stacktrace / full error message
Error in query:
function strpos(unknown) does not exist
LINE 1: ... (1 / nullif(strpos(', ...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 98, in application
response = frappe.api.handle()
File "apps/frappe/frappe/api.py", line 55, in handle
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1627, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/desk/search.py", line 37, in search_link
search_widget(
File "apps/frappe/frappe/desk/search.py", line 216, in search_widget
values = frappe.get_list(
File "apps/frappe/frappe/model/db_query.py", line 255, in build_and_run
return frappe.db.sql(
File "apps/frappe/frappe/database/postgres/database.py", line 209, in sql
return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
psycopg2.errors.UndefinedFunction: function strpos(unknown) does not exist
Additional information
-
The issue affects only PostgreSQL installations.
-
It occurs only in doctypes where “Translate Link Fields” is disabled.
-
When the option is enabled, the search executes successfully even with commas.
-
The issue seems to be related to how relevance-based search expressions are generated for non-translated doctypes.