frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.78k stars 7.31k forks source link

Error: Executing erpnext.patches.v13_0.add_missing_fg_item_for_stock_entry #26845

Closed revant closed 3 years ago

revant commented 3 years ago

Site has no customization

Executing erpnext.patches.v13_0.add_missing_fg_item_for_stock_entry in site.name (_dc036eeb6c0e0341)
Syntax error in query:

                SELECT
                        se.name
                FROM
                        `tabStock Entry` se
                WHERE
                        se.purpose = 'Manufacture' and se.docstatus < 2 and se.work_order in ('WO-Craft-Reliance Hosur-1-08-21-002-001',)
                        and not exists(
                                select name from `tabStock Entry Detail` sed where sed.parent = se.name and sed.is_finished_item = 1
                        )
                Order BY
                        se.posting_date, se.posting_time

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 104, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 19, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 27, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 309, in migrate
    skip_search_index=skip_search_index
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 67, in migrate
    frappe.modules.patch_handler.run_all(skip_failing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all
    run_patch(patch)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 91, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v13_0/add_missing_fg_item_for_stock_entry.py", line 44, in execute
    '''.format(work_orders=tuple(work_orders)))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 243, in sql_list
    return [r[0] for r in self.sql(query, values, debug=debug)]
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 152, in sql
    self._cursor.execute(query)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 775, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')\n\t\t\tand not exists(\n\t\t\t\tselect name from `tabStock Entry Detail` sed where s...' at line 6")
revant commented 3 years ago

Note:

my work order has only 1 element, and it causes the extra comma due to python tuple

work_orders = ('WO-Craft-Reliance Hosur-1-08-21-002-001',)

I hacked up the section for patch to run

    stock_entries = frappe.db.sql_list('''
        SELECT
            se.name
        FROM
            `tabStock Entry` se
        WHERE
            se.purpose = 'Manufacture' and se.docstatus < 2 and se.work_order in ('{work_orders}')
            and not exists(
                select name from `tabStock Entry Detail` sed where sed.parent = se.name and sed.is_finished_item = 1
            )
        Order BY
            se.posting_date, se.posting_time
    '''.format(work_orders=work_orders[0]))
ankush commented 3 years ago

https://github.com/frappe/erpnext/pull/26774