AttributeError: module 'erpnext.controllers.queries' has no attribute 'customer_query'

when i’m doing “bench migrate” its showing an error :
Updating DocTypes for frappe : [========================================] 100%
Updating DocTypes for payments : [========================================] 100%
Updating DocTypes for erpnext : [========================================] 100%
Updating DocTypes for hrms : [========================================] 100%
Updating DocTypes for print_designer: [========================================] 100%
Executing erpnext.patches.v14_0.update_invoicing_period_in_subscription in erp.xcode.ae (_7f499e46ba6bde83)
Queued rebuilding of search index for erp.xcode.ae

Traceback with variables (most recent call last):
File “”, line 198, in _run_module_as_main
mod_name = ‘frappe.utils.bench_helper’
alter_argv = True
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, origin=‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
code = <code object at 0x1ac9de0, file “/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
main_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, origin=‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-311.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.11/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.11/json/init.py’>, ‘os’: <module ‘os’ (frozen)>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.11/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.11/warnings.py’>, ‘Path’: <class ‘pathlib.Path’>, ‘deden…
File “”, line 88, in _run_code
code = <code object at 0x1ac9de0, file “/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
run_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, origin=’/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-311.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.11/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.11/json/init.py’>, ‘os’: <module ‘os’ (frozen)>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.11/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.11/warnings.py’>, ‘Path’: <class ‘pathlib.Path’>, ‘deden…
init_globals = None
mod_name = ‘main
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>, origin=’/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
pkg_name = ‘frappe.utils’
script_name = None
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7fa442f180d0>
fname = ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’
cached = ‘/home/xcode/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-311.pyc’
File “/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 114, in
main()
…skipped… 27 vars
File “/home/xcode/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 20, in main
click.Group(commands=commands)(prog_name=“bench”)
commands = {‘frappe’: , ‘get-frappe-commands’: , ‘get-frappe-help’: }
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 1157, in call
return self.main(*args, **kwargs)
self =
args = ()
kwargs = {‘prog_name’: ‘bench’}
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 1078, in main
rv = self.invoke(ctx)
self =
args = [‘frappe’, ‘migrate’]
prog_name = ‘bench’
complete_var = None
standalone_mode = True
windows_expand_args = True
extra = {}
ctx = <click.core.Context object at 0x7fa4417407d0>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
self =
ctx = <click.core.Context object at 0x7fa4417407d0>
_process_result = <function MultiCommand.invoke.._process_result at 0x7fa44185ce00>
args = [‘migrate’]
cmd_name = ‘frappe’
cmd =
sub_ctx = <click.core.Context object at 0x7fa441888190>
class = <class ‘click.core.MultiCommand’>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
self =
ctx = <click.core.Context object at 0x7fa441888190>
_process_result = <function MultiCommand.invoke.._process_result at 0x7fa441884900>
args =
cmd_name = ‘migrate’
cmd =
sub_ctx = <click.core.Context object at 0x7fa4413d4110>
class = <class ‘click.core.MultiCommand’>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
self =
ctx = <click.core.Context object at 0x7fa4413d4110>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
_Context__self = <click.core.Context object at 0x7fa4413d4110>
_Context__callback = <function migrate at 0x7fa4418ce660>
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
ctx = <click.core.Context object at 0x7fa4413d4110>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/click/decorators.py”, line 33, in new_func
return f(get_current_context(), *args, **kwargs)
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
f = <function migrate at 0x7fa4418ce3e0>
File “/home/xcode/frappe-bench/apps/frappe/frappe/commands/init.py”, line 29, in func
ret = f(frappe.dict(ctx.obj), *args, **kwargs)
ctx = <click.core.Context object at 0x7fa4413d4110>
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
profile = False
f = <function migrate at 0x7fa4418ce340>
File “/home/xcode/frappe-bench/apps/frappe/frappe/commands/site.py”, line 712, in migrate
).run(site=site)
context = {‘sites’: [‘erp.xcode.ae’], ‘force’: False, ‘verbose’: False, ‘profile’: False}
skip_failing = False
skip_search_index = False
activate_by_import = <module ‘traceback_with_variables.activate_by_import’ from ‘/home/xcode/frappe-bench/env/lib/python3.11/site-packages/traceback_with_variables/activate_by_import.py’>
SiteMigration = <class ‘frappe.migrate.SiteMigration’>
site = ‘erp.xcode.ae’
File “/home/xcode/frappe-bench/apps/frappe/frappe/migrate.py”, line 186, in run
self.run_schema_updates()
self = <frappe.migrate.SiteMigration object at 0x7fa43c55a490>
site = ‘erp.xcode.ae’
filelock = <function filelock at 0x7fa42ec3e700>
File “/home/xcode/frappe-bench/apps/frappe/frappe/migrate.py”, line 52, in wrapper
raise e
args = (<frappe.migrate.SiteMigration object at 0x7fa43c55a490>,)
kwargs = {}
method = <function SiteMigration.run_schema_updates at 0x7fa42ec3e160>
File “/home/xcode/frappe-bench/apps/frappe/frappe/migrate.py”, line 44, in wrapper
ret = method(*args, **kwargs)
args = (<frappe.migrate.SiteMigration object at 0x7fa43c55a490>,)
kwargs = {}
method = <function SiteMigration.run_schema_updates at 0x7fa42ec3e160>
File “/home/xcode/frappe-bench/apps/frappe/frappe/migrate.py”, line 121, in run_schema_updates
frappe.modules.patch_handler.run_all(
self = <frappe.migrate.SiteMigration object at 0x7fa43c55a490>
File “/home/xcode/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 76, in run_all
run_patch(patch)
skip_failing = False
patch_type = <PatchType.post_model_sync: ‘post_model_sync’>
executed = {‘press.patches.v0_0_1.set_app_title_from_custom_field’, ‘erpnext.patches.v11_0.add_default_dispatch_notification_template’, ‘erpnext.patches.v14_0.migrate_cost_center_allocations’, ‘press.patches.v0_0_1.set_host_name_for_sites_with_domains’, ‘erpnext.patches.v12_0.set_cwip_and_delete_asset_settings’, “execute:frappe.delete_doc_if_exists(‘DocType’, ‘GCalendar Settings’)”, ‘hrms.patches.v15_0.migrate_loan_type_to_loan_product’, ‘erpnext.patches.v14_0.remove_india_localisation # 14-07-2022’, ‘erpnext.patches.v11_0.rename_production_order_to_work_order’, ‘press.patches.v0_0_1.update_site_config_doc’, ‘press.patches.v0_0_1.mark_deployed_app_releases_as_approved_and_deployable # 2020-22-06’, ‘execute:frappe.get_doc(“User”, “Guest”).save()’, ‘erpnext.patches.v13_0.set_work_order_qty_in_so_from_mr’, ‘erpnext.patches.v12_0.set_permission_einvoicing’, ‘erpnext.patches.v11_1.setup_guardian_role’, ‘press.press.doctype.virtual_machine.patches.populate_volumes_table’, 'erpnext.patches.v11_0.create

run_patch = <function run_all..run_patch at 0x7fa42e54c180>
patches = [“execute:frappe.get_doc(‘Role’, ‘Guest’).save() # remove desk access”, ‘frappe.core.doctype.role.patches.v13_set_default_desk_properties’, ‘frappe.patches.v14_0.update_workspace2 # 06.06.2023’, ‘frappe.patches.v14_0.drop_data_import_legacy’, ‘frappe.patches.v14_0.copy_mail_data #08.03.21’, ‘frappe.patches.v14_0.update_github_endpoints #08-11-2021’, ‘frappe.patches.v14_0.remove_db_aggregation’, ‘frappe.patches.v14_0.update_color_names_in_kanban_board_column’, ‘frappe.patches.v14_0.update_is_system_generated_flag’, ‘frappe.patches.v14_0.update_auto_account_deletion_duration’, ‘frappe.patches.v14_0.update_integration_request’, ‘frappe.patches.v14_0.set_document_expiry_default’, ‘frappe.patches.v14_0.delete_data_migration_tool’, ‘frappe.patches.v14_0.set_suspend_email_queue_default’, ‘frappe.patches.v14_0.different_encryption_key’, ‘frappe.patches.v14_0.update_multistep_webforms’, “execute:frappe.delete_doc(‘Page’, ‘background_jobs’, ignore_missing=True, force=True)”, 'frappe.patches.v14

patch = ‘erpnext.patches.v14_0.update_invoicing_period_in_subscription’
File “/home/xcode/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 62, in run_patch
if not run_single(patchmodule=patch):
patch = ‘erpnext.patches.v14_0.update_invoicing_period_in_subscription’
skip_failing = False
File “/home/xcode/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 152, in run_single
return execute_patch(patchmodule, method, methodargs)
patchmodule = ‘erpnext.patches.v14_0.update_invoicing_period_in_subscription’
method = None
methodargs = None
force = False
conf =
File “/home/xcode/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 188, in execute_patch
_patch()
patchmodule = ‘erpnext.patches.v14_0.update_invoicing_period_in_subscription’
method = None
methodargs = None
has_patch_file = True
patch = ‘erpnext.patches.v14_0.update_invoicing_period_in_subscription.execute’
docstring = ‘’
_patch = <function execute at 0x7fa42e54d8a0>
start_time = 793232.337871114
File “/home/xcode/frappe-bench/apps/erpnext/erpnext/patches/v14_0/update_invoicing_period_in_subscription.py”, line 8, in execute
).where(subscription.generate_invoice_at_period_start == 1).run()
subscription = Table(‘tabSubscription’)
File “/home/xcode/frappe-bench/apps/frappe/frappe/query_builder/utils.py”, line 87, in execute_query
result = frappe.db.sql(query, params, *args, **kwargs) # nosemgrep
query = ‘UPDATE tabSubscription SET generate_invoice_at=%(param1)s WHERE generate_invoice_at_period_start=1’
args = ()
kwargs = {}
child_queries =
params = {‘param1’: ‘Beginning of the current subscription period’}
execute_child_queries = <function patch_query_execute..execute_child_queries at 0x7fa42ec3e520>
prepare_query = <function patch_query_execute..prepare_query at 0x7fa42ec3e7a0>
File “/home/xcode/frappe-bench/apps/frappe/frappe/database/database.py”, line 234, in sql
self._cursor.execute(query, values)
self = <frappe.database.mariadb.database.MariaDBDatabase object at 0x7fa42eefdc50>
query = ‘UPDATE tabSubscription SET generate_invoice_at=%(param1)s WHERE generate_invoice_at_period_start=1’
values = {‘param1’: ‘Beginning of the current subscription period’}
as_dict = 0
as_list = 0
debug = False
ignore_ddl = 0
auto_commit = 0
update = None
explain = False
run = True
pluck = False
as_iterator = False
trace_id = None
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/cursors.py”, line 153, in execute
result = self._query(query)
self = <pymysql.cursors.Cursor object at 0x7fa42ef00d50>
query = “UPDATE tabSubscription SET generate_invoice_at=‘Beginning of the current subscription period’ WHERE generate_invoice_at_period_start=1”
args = {‘param1’: ‘Beginning of the current subscription period’}
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/cursors.py”, line 322, in _query
conn.query(q)
self = <pymysql.cursors.Cursor object at 0x7fa42ef00d50>
q = “UPDATE tabSubscription SET generate_invoice_at=‘Beginning of the current subscription period’ WHERE generate_invoice_at_period_start=1”
conn = <pymysql.connections.Connection object at 0x7fa43f074d50>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py”, line 558, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
self = <pymysql.connections.Connection object at 0x7fa43f074d50>
sql = b"UPDATE tabSubscription SET generate_invoice_at=‘Beginning of the current subscription period’ WHERE generate_invoice_at_period_start=1"
unbuffered = False
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py”, line 822, in _read_query_result
result.read()
self = <pymysql.connections.Connection object at 0x7fa43f074d50>
unbuffered = False
result = <pymysql.connections.MySQLResult object at 0x7fa42e610a90>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py”, line 1200, in read
first_packet = self.connection._read_packet()
self = <pymysql.connections.MySQLResult object at 0x7fa42e610a90>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py”, line 772, in _read_packet
packet.raise_for_error()
self = <pymysql.connections.Connection object at 0x7fa43f074d50>
packet_type = <class ‘pymysql.protocol.MysqlPacket’>
buff = bytearray(b"\xff\x1e\x04#42S22Unknown column 'generate_invoice_at_period_start' in 'where clause'“)
packet_header = b’L\x00\x00\x01’
btrl = 76
btrh = 0
packet_number = 1
bytes_to_read = 76
recv_data = b”\xff\x1e\x04#42S22Unknown column ‘generate_invoice_at_period_start’ in ‘where clause’"
packet = <pymysql.protocol.MysqlPacket object at 0x7fa42e6340a0>
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
self = <pymysql.protocol.MysqlPacket object at 0x7fa42e6340a0>
errno = 1054
File “/home/xcode/frappe-bench/env/lib/python3.11/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
data = b"\xff\x1e\x04#42S22Unknown column ‘generate_invoice_at_period_start’ in ‘where clause’"
errno = 1054
errval = “Unknown column ‘generate_invoice_at_period_start’ in ‘where clause’”
errorclass = <class ‘pymysql.err.OperationalError’>
pymysql.err.OperationalError: (1054, “Unknown column ‘generate_invoice_at_period_start’ in ‘where clause’”)

also why i’m doing that because i had an error when i’m trying to select the customer from customers list on the sales invoices.
i’ve tried to create a new site , it’s showing same issue :
“AttributeError: module ‘erpnext.controllers.queries’ has no attribute ‘customer_query’”

Logs reports:

App Versions

{
	"erpnext": "15.20.5",
	"frappe": "15.20.0",
	"hrms": "15.19.0",
	"payments": "0.0.1",
	"print_designer": "1.2.0"
}

Route

Form/Sales Invoice/new-sales-invoice-witivtswga

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
           ^^^^^^^^^^^^^^^^
  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 1718, in call
    return fn(*args, **newargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/desk/search.py", line 47, in search_link
    results = search_widget(
              ^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/desk/search.py", line 93, in search_widget
    is_whitelisted(frappe.get_attr(query))
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 1708, in get_attr
    return getattr(get_module(modulename), methodname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'erpnext.controllers.queries' has no attribute 'customer_query'

Request Data

{
	"type": "POST",
	"args": {
		"txt": "",
		"doctype": "Customer",
		"ignore_user_permissions": 0,
		"reference_doctype": "Sales Invoice",
		"query": "erpnext.controllers.queries.customer_query"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.search.search_link",
	"request_id": null
}

Response Data

{
	"exception": "AttributeError: module 'erpnext.controllers.queries' has no attribute 'customer_query'",
	"exc_type": "AttributeError"
}

the issue has been solved by these comments.
1- bench update --patch
2- bench --site site.local build
3- bench --site site.local migrate

if the first solution didn’t work with you you need to do :

If the generate_invoice_at column appears to be empty, it’s possible that the error you’re encountering is related to a missing column generate_invoice_at_period_start, which the patch is attempting to use in its WHERE clause.

To confirm whether the column generate_invoice_at_period_start exists in the tabSubscription table, you can use the SQL query mentioned earlier:

sql

Copy code

SHOW COLUMNS FROM `tabSubscription`;

Look for the column named generate_invoice_at_period_start in the output. If it doesn’t exist, that would explain the error you’re encountering, as the patch is trying to reference a column that isn’t present in the table.

If the column is indeed missing, you’ll need to add it to the table. You can use an SQL ALTER TABLE command to add the column, similar to the following:

sql

Copy code

ALTER TABLE `tabSubscription` ADD COLUMN `generate_invoice_at_period_start` INT DEFAULT 0;

Once you’ve added the column, you can rerun the patch to see if the error persists. If the patch relies on the presence of this column, adding it should resolve the issue.