Dashboard search not working because of the change in query pattern from v5 and upwards in some cases

In the Dashboard model, the querying of data was switched from using groupBy in v4.0.2 to distinct in v5.0.0.
Due to this dashboard serializer give an error because the queries miss out on some users while fetching the user information, which ultimately fail when we do user.to_dict() later on.

This will depend on stored data as it might not generate in every case. For some of the cases it might actually work.

Because of the these changes the new queries that get generated to query the data are

SELECT DISTINCT
    dashboards.updated_at AS dashboards_updated_at,
    dashboards.created_at AS dashboards_created_at,
    dashboards.id AS dashboards_id,
    dashboards.version AS dashboards_version,
    dashboards.org_id AS dashboards_org_id,
    dashboards.slug AS dashboards_slug,
    dashboards.name AS dashboards_name,
    dashboards.user_id AS dashboards_user_id,
    dashboards.layout AS dashboards_layout,
    dashboards.dashboard_filters_enabled AS dashboards_dashboard_filters_enabled,
    dashboards.is_archived AS dashboards_is_archived,
    dashboards.is_draft AS dashboards_is_draft,
    dashboards.tags AS dashboards_tags
FROM
    dashboards
    LEFT OUTER JOIN widgets ON dashboards.id = widgets.dashboard_id
    LEFT OUTER JOIN visualizations ON visualizations.id = widgets.visualization_id
    LEFT OUTER JOIN queries ON queries.id = visualizations.query_id
    LEFT OUTER JOIN data_source_groups ON queries.data_source_id = data_source_groups.data_source_id
WHERE
    dashboards.is_archived = FALSE
    AND(data_source_groups.group_id IN(2, 1)
        OR dashboards.user_id = 21
        OR widgets.dashboard_id IS NOT NULL
        AND widgets.visualization_id IS NULL)
    AND 1 = dashboards.org_id
    AND(dashboards.user_id = 21
        OR dashboards.is_draft = FALSE)
    AND dashboards.name ILIKE '%et%'
LIMIT 20 OFFSET 0;

and

SELECT
    users.profile_image_url AS users_profile_image_url,
    users.id AS users_id,
    users.name AS users_name,
    anon_1.dashboards_user_id AS anon_1_dashboards_user_id
FROM ( SELECT DISTINCT
        dashboards.user_id AS dashboards_user_id
    FROM
        dashboards
    LEFT OUTER JOIN widgets ON dashboards.id = widgets.dashboard_id
    LEFT OUTER JOIN visualizations ON visualizations.id = widgets.visualization_id
    LEFT OUTER JOIN queries ON queries.id = visualizations.query_id
    LEFT OUTER JOIN data_source_groups ON queries.data_source_id = data_source_groups.data_source_id
WHERE
    dashboards.is_archived = FALSE
    AND(data_source_groups.group_id IN(2, 1)
        OR dashboards.user_id = 21
        OR widgets.dashboard_id IS NOT NULL
        AND widgets.visualization_id IS NULL)
    AND 1 = dashboards.org_id
    AND(dashboards.user_id = 21
        OR dashboards.is_draft = FALSE)
    AND dashboards.name ILIKE '%et%'
LIMIT 20 OFFSET 0) AS anon_1
    JOIN users ON users.id = anon_1.dashboards_user_id
ORDER BY
    anon_1.dashboards_user_id;

Here in the second query we are using distinct on user_id which then has limit, because of which first query has different users and second query different. However reverting to using groupBy does solve the issue.