From 2c7d116ce0d8c28213ba542b7a9c09cb83e0eddd Mon Sep 17 00:00:00 2001 From: Dennis Wambua Date: Tue, 16 Nov 2021 16:23:51 +0300 Subject: [PATCH] Change to left join to handle situaton where submission was made anonymously --- onadata/libs/data/query.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/onadata/libs/data/query.py b/onadata/libs/data/query.py index 2fafdfcf49..16f7053022 100644 --- a/onadata/libs/data/query.py +++ b/onadata/libs/data/query.py @@ -92,14 +92,14 @@ def _postgres_count_group(field, name, xform, data_view=None): if data_view: additional_filters = _additional_data_view_filters(data_view) - # Use inner join to the auth user model for better performance. + # Use left join to the auth user model for better performance. if field == "_submitted_by": string_args["json"] = "au.username" - string_args["inner_join"] = "i INNER JOIN auth_user au ON au.id = i.user_id" + string_args["join"] = "i LEFT JOIN auth_user au ON au.id = i.user_id" restricted_string = _restricted_query(xform) sql_query = "SELECT %(json)s AS \"%(name)s\", COUNT(*) AS count FROM " \ - "%(table)s %(inner_join)s WHERE " + restricted_string + \ + "%(table)s %(join)s WHERE " + restricted_string + \ " AND deleted_at IS NULL " + additional_filters + " GROUP BY %(json)s"\ " ORDER BY %(json)s" sql_query = sql_query % string_args @@ -170,7 +170,7 @@ def _query_args(field, name, xform, group_by=None): 'name': name, 'restrict_field': 'xform_id', 'restrict_value': xform.pk, - 'inner_join': '', + 'join': '', } if xform.is_merged_dataset: