Item save error

If Item has multiple uoms in the master we can’t update or create a new Item.

The responsible code seems this one erpnext/erpnext/stock/doctype/item/item.py at 2b0b24f7c34f6aadec0a334c73263bdf065656f7 · frappe/erpnext · GitHub.

This query causes an exception:

			select (first.value / second.value) as value
			from `tabUOM Conversion Factor` first
			join `tabUOM Conversion Factor` second
				on first.from_uom = second.from_uom
			where
				first.to_uom = %(to_uom)s
				and second.to_uom = %(from_uom)s
			limit 1

Exception: (1054, “Unknown column ‘first.value’ in ‘field list’”)
But “tabUOM Conversion Factor” table has “value” column.

We can run the query in the System Console if table alias is set with backtrick (ie first and second) .
So this query doesn’t generate any error.

			select (first.value / second.value) as value
			from `tabUOM Conversion Factor` `first`
			join `tabUOM Conversion Factor` `second`
				on first.from_uom = second.from_uom
			where
				first.to_uom = %(to_uom)s
				and second.to_uom = %(from_uom)s
			limit 1

It seems that code is updated 2 years ago and we were updating Item conversion factors yesterday, I can’t find the real reason behind it. We are on Frappe Cloud so we can’t update the code.

Do you have any idea why is that causing this error today? Can we do anything about it on the Frappe Cloud?

Hi @TurkerTunali,
Hope you are doing well.

We checked on the frappe cloud side but we don’t face any types of errors.
Please check it.

If not update your site then please update it and check it. (Please first take a backup).

I also did check in the local system but don’t have any faced issues.

Have a good day!
Thank You!

1 Like

Our versions are same

ERPNext: v14.20.3 (HEAD)
Frappe Framework: v14.31.0 (HEAD)

We couldn’t find the reason?

Hmm :thinking:,

I think, please migrate your site (Please first take a backup).

Maybe will solve your issue.

Thank You!

I’ve found the reason.
ERPNext_Recorder_Err2

It generates the error only if recorder is active :thinking:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 66, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 83, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1607, in call
    return fn(*args, **newargs)
  File "apps/erpnext/erpnext/stock/doctype/item/item.py", line 1255, in get_uom_conv_factor
    intermediate_match = frappe.db.sql(
  File "apps/frappe/frappe/recorder.py", line 35, in sql
    explain_result = frappe.db._sql(f"EXPLAIN {query}", as_dict=True)
  File "apps/frappe/frappe/database/database.py", line 219, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 158, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 325, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 549, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 779, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1164, in read
    self._read_result_packet(first_packet)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1240, in _read_result_packet
    self._read_rowdata_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1274, in _read_rowdata_packet
    packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 729, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1054, "Unknown column 'first.value' in 'field list'")
request.js:457:14