Coding-with-Adam / response-reporting-dashboard

4 stars 1 forks source link

Admin Menu - Password Reset #22

Open JorgeMiguelGomes opened 1 month ago

JorgeMiguelGomes commented 1 month ago

What happens

When clicking on "Password Reset" the following error is triggered


  File "/opt/app/pages/admin-menu.py", line 719, in update_resets_request_table
    grid_row_data = pending_request_table.to_dict("records")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ProgrammingError' object has no attribute 'to_dict'````

# What is desired 

- That the error is fixed
- That the other functions are checked in order to make sure that all the tables are working as expected 
supernyv commented 1 month ago

Hi @Jorge,

This error could indicate a table is missing from the database or something similar, because the only scenario this error could arise is if the SQL query is unable to fetch something from the database (even if no data exists in the target tables, empty table would still work because the query would fetch the column names). Can you test the SQL Query below on the database itself and see if it works without returning an error?

        WITH reset_counts_cte AS(
    SELECT
        work_email,
        COUNT(id_request) AS resets_count
    FROM password_reset_request WHERE admin_decision = 'Approved'
    GROUP BY work_email
    ),
    analytics_cte AS(
    SELECT
        pr.id_request,
        pr.work_email,
        vt.first_name,
        vt.last_name,
        vt.affiliation_name,
        pr.request_date,
        pr.reset_reason,
        DATEDIFF(
            pr.request_date,
            LAG(pr.request_date) OVER (PARTITION BY pr.work_email ORDER BY pr.request_date)
            ) AS days_since_last_request,
        COALESCE(rc.resets_count, 0) AS resets_count,
        reset_completed
    FROM
        vetted_user AS vt
        INNER JOIN
        password_reset_request AS pr
        ON pr.work_email = vt.work_email
        LEFT JOIN reset_counts_cte AS rc
        ON rc.work_email = vt.work_email
    )
    SELECT * FROM analytics_cte WHERE reset_completed = 0;
JorgeMiguelGomes commented 1 month ago

@tomahock can you please check? Thanks!