-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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!: map columns correctly in query report via fieldnames #26500
Conversation
@@ -146,7 +146,7 @@ def execute_query_report(self, filters): | |||
|
|||
check_safe_sql_query(self.query) | |||
|
|||
result = [list(t) for t in frappe.db.sql(self.query, filters)] | |||
result = frappe.db.sql(self.query, filters, as_dict=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ummm, isn't this different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list[list[Any]] -> [list[dict[str, Any]]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the point 😆 - will update the description in a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code automatically handles it down the line btw:
frappe/frappe/desk/query_report.py
Lines 127 to 134 in c973d08
if result and isinstance(result[0], list | tuple): | |
for row in result: | |
row_obj = {} | |
for idx, column_name in enumerate(column_names): | |
row_obj[column_name] = row[idx] | |
data.append(row_obj) | |
else: | |
data = result |
tested this with aliased columns as well as with stuff like Screencast.2024-05-23.02.35.01.mp4 |
side note(s):
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing. |
This pr helps in mapping the report columns correctly as defined in the column table for
query report
type. Previously it used to map the columns in the sequence they're defined ..not corresponding with the fieldnamesbefore:
Screencast.2024-05-23.02.00.03.mp4
after:
Screencast.2024-05-23.01.58.27.mp4
This could be considered a breaking change if people have written queries without providing appropriate fieldnames in the column table.