8848digital / erpnext

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

Inventory Dimension: When the user saves a new Inventory Dimension record, an error is thrown. #9

Open shyamrathod12 opened 1 week ago

shyamrathod12 commented 1 week ago

Information about bug

Inventory Dimension: When the user saves a new Inventory Dimension record, an error is thrown. psycopg2.errors.InvalidColumnReference: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 5: order by "tabDocField"."modified" ASC ^ Screenshot from 2024-09-09 18-36-40

Module

stock

Version

ERPNext: v15.34.0 (version-15)

Frappe Framework: v15.40.0 (version-15)

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

### App Versions

{
    "erpnext": "15.34.0",
    "frappe": "15.40.0"
}

Route

Form/Inventory Dimension/new-inventory-dimension-fmmujbkmyr

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 114, 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 1775, 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/form/save.py", line 39, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 337, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 359, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 315, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1128, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py", line 148, in on_update
    self.add_custom_fields()
  File "apps/erpnext/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py", line 199, in add_custom_fields
    for doctype in get_inventory_documents():
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py", line 293, in get_inventory_documents
    return frappe.get_all(
  File "apps/frappe/frappe/__init__.py", line 2064, in get_all
    return get_list(doctype, *args, **kwargs)
  File "apps/frappe/frappe/__init__.py", line 2039, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
  File "apps/frappe/frappe/model/db_query.py", line 191, in execute
    result = self.build_and_run()
  File "apps/frappe/frappe/model/db_query.py", line 232, in build_and_run
    return frappe.db.sql(
  File "apps/frappe/frappe/database/postgres/database.py", line 219, in sql
    return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
  File "apps/frappe/frappe/database/database.py", line 229, in sql
    self._cursor.execute(query, values)
psycopg2.errors.InvalidColumnReference: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 5:     order by "tabDocField"."modified" ASC
                     ^

Request Data

{
    "type": "POST",
    "args": {
        "doc": "{\"docstatus\":0,\"doctype\":\"Inventory Dimension\",\"name\":\"new-inventory-dimension-fmmujbkmyr\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"disabled\":0,\"apply_to_all_doctypes\":1,\"validate_negative_stock\":0,\"type_of_transaction\":\"\",\"istable\":0,\"reqd\":0,\"dimension_name\":\"Test\",\"reference_document\":\"Sales Invoice\"}",
        "action": "Save"
    },
    "btn": {
        "jQuery370056736936911566891": {
            "events": {
                "click": [
                    {
                        "type": "click",
                        "origType": "click",
                        "guid": 5492,
                        "namespace": ""
                    }
                ]
            }
        }
    },
    "freeze": true,
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/frappe.desk.form.save.savedocs",
    "request_id": null
}

Response Data

{
    "exception": "",
    "exc_type": "InvalidColumnReference",
    "_exc_source": "erpnext (app)",
    "_debug_messages": "[\"Error in query:\\nfor SELECT DISTINCT, ORDER BY expressions must appear in select list\\nLINE 5:     order by \\\"tabDocField\\\".\\\"modified\\\" ASC\\n                     ^\\n\"]"
}
nilesh8848 commented 1 week ago

Fixed by adding parent and modified fields instead of distinct parent, which was throwing an error in get_inventory_documents function