frappe / insights

Open source analytics / business intelligence tool (BI)
https://frappe.io/insights
GNU Affero General Public License v3.0
368 stars 173 forks source link

GroupingError #244

Closed karanbosamia closed 1 week ago

karanbosamia commented 2 months ago

Description of issue:

Site: insights.test
Form Dict: {'doctype': 'Insights Query', 'fields': ['name', 'title', 'status', 'is_assisted_query', 'is_native_query', 'is_script_query', 'is_stored', 'data_source', 'creation', 'owner', 'owner_name', 'owner_image', 'chart_type'], 'filters': {}, 'order_by': 'creation desc', 'start': 0, 'limit': 50, 'limit_start': 0, 'limit_page_length': 50, 'debug': 0, 'cmd': 'insights.api.queries.get_queries'}
Traceback (most recent call last):
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1803, in call
    return fn(*args, **newargs)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "/home/karan/frappe/frappe-bench/apps/insights/insights/decorators.py", line 15, in wrapper
    return function(*args, **kwargs)
  File "/home/karan/frappe/frappe-bench/apps/insights/insights/api/queries.py", line 21, in get_queries
    return (
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/query_builder/utils.py", line 84, in execute_query
    result = frappe.db.sql(query, params, *args, **kwargs)  # nosemgrep
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/database/postgres/database.py", line 220, in sql
    return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
  File "/home/karan/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 237, in sql
    self._cursor.execute(query, values)
psycopg2.errors.GroupingError: column "tabUser.full_name" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...hts Query"."creation","tabInsights Query"."owner","tabUser"...

Here,

https://github.com/frappe/insights/blob/7950b5a9215e4bab5afbc656af53fec272e0aa93/insights/api/queries.py#L45

the issue is happening while grouping it. It got resolved by placing

User.full_name.as_("owner_name"),
User.user_image.as_("owner_image"),
QueryChart.chart_type,
DataSource.title.as_("data_source_title"),

in group by.

nextchamp-saqib commented 1 week ago

fixed: 6e95d772e8ac8b01d9cfdb23b61d4a0008fdd8eb