From 0d645f2eea5a364e3ede1d26a68acab78ad60a85 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 17:48:49 +0530 Subject: [PATCH 1/2] fix: sort prepared report filters (#19267) (#19270) backport of https://github.com/frappe/frappe/pull/19265 (cherry picked from commit b3e16b8c4739d958f7cb8dd461cfb4249296267a) Co-authored-by: Ankush Menat --- .../doctype/prepared_report/prepared_report.py | 13 ++++++++++++- frappe/desk/query_report.py | 14 ++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/frappe/core/doctype/prepared_report/prepared_report.py b/frappe/core/doctype/prepared_report/prepared_report.py index 0b8e25229d5c..51f6cd63a1f1 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.py +++ b/frappe/core/doctype/prepared_report/prepared_report.py @@ -68,7 +68,7 @@ def get_reports_in_queued_state(report_name, filters): "Prepared Report", filters={ "report_name": report_name, - "filters": json.dumps(json.loads(filters)), + "filters": process_filters_for_prepared_report(filters), "status": "Queued", }, ) @@ -102,6 +102,17 @@ def delete_prepared_reports(reports): ) +def process_filters_for_prepared_report(filters): + if isinstance(filters, str): + filters = json.loads(filters) + + # This looks like an insanity but, without this it'd be very hard to find Prepared Reports matching given condition + # We're ensuring that spacing is consistent. e.g. JS seems to put no spaces after ":", Python on the other hand does. + # We are also ensuring that order of keys is same so generated JSON string will be identical too. + # PS: frappe.as_json sorts keys + return frappe.as_json(filters, indent=None, separators=(",", ":")) + + def create_json_gz_file(data, dt, dn): # Storing data in CSV file causes information loss # Reports like P&L Statement were completely unsuable because of this diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index f885c97e6d2f..81b113dcd703 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -147,6 +147,10 @@ def normalize_result(result, columns): @frappe.whitelist() def background_enqueue_run(report_name, filters=None, user=None): """run reports in background""" + from frappe.core.doctype.prepared_report.prepared_report import ( + process_filters_for_prepared_report, + ) + if not user: user = frappe.session.user report = get_report_doc(report_name) @@ -154,9 +158,7 @@ def background_enqueue_run(report_name, filters=None, user=None): { "doctype": "Prepared Report", "report_name": report_name, - # This looks like an insanity but, without this it'd be very hard to find Prepared Reports matching given condition - # We're ensuring that spacing is consistent. e.g. JS seems to put no spaces after ":", Python on the other hand does. - "filters": json.dumps(json.loads(filters)), + "filters": process_filters_for_prepared_report(filters), "ref_report_doctype": report_name, "report_type": report.report_type, "query": report.query, @@ -271,6 +273,10 @@ def add_custom_column_data(custom_columns, result): def get_prepared_report_result(report, filters, dn="", user=None): + from frappe.core.doctype.prepared_report.prepared_report import ( + process_filters_for_prepared_report, + ) + latest_report_data = {} doc = None if dn: @@ -282,7 +288,7 @@ def get_prepared_report_result(report, filters, dn="", user=None): "Prepared Report", filters={ "status": "Completed", - "filters": json.dumps(filters), + "filters": process_filters_for_prepared_report(filters), "owner": user, "report_name": report.get("custom_report") or report.get("report_name"), }, From 17f94ac9979c30d2e9c4a56489431147dfca6445 Mon Sep 17 00:00:00 2001 From: Frappe PR Bot Date: Tue, 13 Dec 2022 12:20:11 +0000 Subject: [PATCH 2/2] chore(release): Bumped to Version 14.19.1 ## [14.19.1](https://github.com/frappe/frappe/compare/v14.19.0...v14.19.1) (2022-12-13) ### Bug Fixes * sort prepared report filters ([#19267](https://github.com/frappe/frappe/issues/19267)) ([#19270](https://github.com/frappe/frappe/issues/19270)) ([0d645f2](https://github.com/frappe/frappe/commit/0d645f2eea5a364e3ede1d26a68acab78ad60a85)) --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index fc72640a6f88..96ecd65558d0 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -42,7 +42,7 @@ ) from .utils.lazy_loader import lazy_import -__version__ = "14.19.0" +__version__ = "14.19.1" __title__ = "Frappe Framework" controllers = {}