Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Sales Register): incorrect query with dimensions #31242

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

ankush
Copy link
Member

@ankush ankush commented Jun 6, 2022

If the accounting dimension is also part of the default filters then same the query is repeated with incorrect syntax.

e.g. item_group = (child1, child2) instead of in query.

fix: don't add default filters if they are part of the dimensions to be added.

App Versions

{
	"erpnext": "14.0.0-dev",
	"frappe": "14.0.0-dev"
}

Route

query-report/Sales Register

Trackeback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 67, 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 39, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 77, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1502, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/__init__.py", line 759, in wrapper_fn
    retval = fn(*args, **get_newargs(fn, kwargs))
  File "apps/frappe/frappe/desk/query_report.py", line 252, in run
    result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field)
  File "apps/frappe/frappe/__init__.py", line 759, in wrapper_fn
    retval = fn(*args, **get_newargs(fn, kwargs))
  File "apps/frappe/frappe/desk/query_report.py", line 86, in generate_report_result
    res = get_report_result(report, filters) or []
  File "apps/frappe/frappe/desk/query_report.py", line 67, in get_report_result
    res = report.execute_script_report(filters)
  File "apps/frappe/frappe/core/doctype/report/report.py", line 142, in execute_script_report
    res = self.execute_module(filters)
  File "apps/frappe/frappe/core/doctype/report/report.py", line 159, in execute_module
    return frappe.get_attr(method_name)(frappe._dict(filters))
  File "apps/erpnext/erpnext/accounts/report/sales_register/sales_register.py", line 17, in execute
    return _execute(filters)
  File "apps/erpnext/erpnext/accounts/report/sales_register/sales_register.py", line 24, in _execute
    invoice_list = get_invoices(filters, additional_query_columns)
  File "apps/erpnext/erpnext/accounts/report/sales_register/sales_register.py", line 419, in get_invoices
    return frappe.db.sql(
  File "apps/frappe/frappe/database/database.py", line 169, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.9/site-packages/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "env/lib/python3.9/site-packages/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "env/lib/python3.9/site-packages/pymysql/connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.9/site-packages/pymysql/connections.py", line 775, in _read_query_result
    result.read()
  File "env/lib/python3.9/site-packages/pymysql/connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (4078, "Illegal parameter data types varchar and row for operation '='")

Request Data

{
	"type": "GET",
	"args": {
		"report_name": "Sales Register",
		"filters": "{\"from_date\":\"2022-05-06\",\"to_date\":\"2022-06-06\",\"company\":\"Wind Power LLC\",\"item_group\":\"DENTAL\"}"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.query_report.run"
}

Response Data

{
	"exception": "pymysql.err.OperationalError: (4078, \"Illegal parameter data types varchar and row for operation '='\")"
}

If accounting dimension is also part of the default filters then same
query is repeated with incorrect syntax.

e.g. `item_group = (child1, child2)` instead of `in` query.

fix: don't add default filter if they are part of dimensions to be
added.
@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Jun 6, 2022
@ankush ankush removed the needs-tests This PR needs automated unit-tests. label Jun 6, 2022
@codecov
Copy link

codecov bot commented Jun 6, 2022

Codecov Report

Merging #31242 (c3219eb) into develop (a8c1b01) will decrease coverage by 0.05%.
The diff coverage is 91.66%.

@@             Coverage Diff             @@
##           develop   #31242      +/-   ##
===========================================
- Coverage    63.33%   63.27%   -0.06%     
===========================================
  Files          986      986              
  Lines        67405    67405              
===========================================
- Hits         42693    42653      -40     
- Misses       24712    24752      +40     
Impacted Files Coverage Δ
...t/accounts/report/sales_register/sales_register.py 73.09% <91.66%> (+2.33%) ⬆️
.../report/delayed_item_report/delayed_item_report.py 60.78% <0.00%> (-35.30%) ⬇️
...e_sales_analytics/supplier_wise_sales_analytics.py 57.37% <0.00%> (-32.79%) ⬇️
...rial_no_valuation/incorrect_serial_no_valuation.py 59.64% <0.00%> (-26.32%) ⬇️
...tch_item_expiry_status/batch_item_expiry_status.py 67.92% <0.00%> (-24.53%) ⬇️
...wise_balance_history/batch_wise_balance_history.py 67.79% <0.00%> (-22.04%) ⬇️
erpnext/accounts/doctype/bank/bank.py 71.42% <0.00%> (-14.29%) ⬇️
...rpnext/accounts/doctype/shareholder/shareholder.py 80.00% <0.00%> (-10.00%) ⬇️
...saction/incorrect_balance_qty_after_transaction.py 88.37% <0.00%> (-9.31%) ⬇️
.../fifo_queue_vs_qty_after_transaction_comparison.py 86.20% <0.00%> (-8.63%) ⬇️
... and 32 more

@deepeshgarg007
Copy link
Member

@Mergifyio backport version-13-hotfix

@mergify
Copy link
Contributor

mergify bot commented Jun 6, 2022

backport version-13-hotfix

✅ Backports have been created

ankush added a commit that referenced this pull request Jun 6, 2022
#31251)

fix(Sales Register): incorrect query with dimensions

If accounting dimension is also part of the default filters then same
query is repeated with incorrect syntax.

e.g. `item_group = (child1, child2)` instead of `in` query.

fix: don't add default filter if they are part of dimensions to be
added.

(cherry picked from commit c3219eb)

Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot pushed a commit that referenced this pull request Jun 7, 2022
# [13.33.0](v13.32.0...v13.33.0) (2022-06-07)

### Bug Fixes

* Close unsecured terms loans ([d6d1d79](d6d1d79))
* Consider only Approved leave applications in LWP, Employee Benefit calculations ([7f84c86](7f84c86))
* display currencies in validation message. ([ef22337](ef22337))
* incorrect billed_qty in sales order analysis report when multiple delivery notes for item (backport [#31194](#31194)) ([#31250](#31250)) ([3b1f6da](3b1f6da))
* incorrect LWP calculation for half days in employee benefit application ([10f0c93](10f0c93))
* **India:** GSTIN filter in GSTR-1 report ([abe9fe7](abe9fe7))
* **India:** Supplies from composite dealer not showing up ([15712c7](15712c7))
* **job card:** only hold during draft state (backport [#31243](#31243)) ([#31249](#31249)) ([a7fc278](a7fc278))
* **Leave Application:** 'Cancelled' status shown as 'Open' in list view ([8b48d45](8b48d45))
* leave balance for earned leaves in backdated Leave Application dashboard (backport [#31253](#31253)) ([#31256](#31256)) ([a22d92f](a22d92f))
* only fetch membership expiry if not already set in `member.js` ([#31259](#31259)) ([d433784](d433784))
* Parent dimension filters in orders ([b3cbcd8](b3cbcd8))
* Pluralize year text instead of optional bracket (backport [#31210](#31210)) ([#31212](#31212)) ([b31709c](b31709c))
* re-validate warehouse after 'update items' (backport [#31203](#31203)) ([#31206](#31206)) ([3a718c7](3a718c7))
* remove leave policy assignment creation patch (backport [#31097](#31097)) ([#31204](#31204)) ([4aeb448](4aeb448))
* Remove redundant query ([3c4cf59](3c4cf59))
* Reverse provisional entries on Purchase Invoice cancel ([1fba432](1fba432))
* **Sales Register:** incorrect query with dimensions (backport [#31242](#31242)) ([#31251](#31251)) ([0badfc8](0badfc8))
* Simply cancel reverse entries ([100b8d9](100b8d9))

### Features

* **india:** Improve E-way Bill Cancellation. ([#31088](#31088)) ([622d25e](622d25e))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants