Skip to content

PMS dashboard widgets throw JS errors on empty data (message-only JSON) #923

@mfamularopsyc

Description

@mfamularopsyc

Description

Summary

On a fresh install with little/no PMS data, some dashboard charts log JavaScript errors and fail to render gracefully. The PMS endpoints return 200 OK with a message-only JSON body (e.g., {"message":"No records available at the moment."}), while the front-end assumes labels/datasets arrays and calls .length on undefined. Charts that do have data render fine.

Environment

  • Horilla: branch 1.0, commit 7560e935
  • Python: 3.12 • Gunicorn: 23.0.0
  • OS/Web: Ubuntu + Nginx 1.24 (behind AWS CloudFront)
  • DB: AWS RDS PostgreSQL 16.8
  • Cache/Sessions: Redis (AWS ElastiCache 7.1) via django-redis
  • Site: https://hr.***.net/

Notes

  • This occurs only for widgets with no data; other charts render correctly.

Steps to Reproduce

Steps to Reproduce

  1. Fresh instance (no PMS objectives/feedback/key results yet).
  2. Log in → open Dashboard.
  3. Check DevTools Console and Network (XHR).

Expected Behavior

Expected Behavior

Empty PMS widgets should not throw errors. Prefer one of:

  • Backend: return a consistent empty shape, e.g.

    {"labels": [], "datasets": []}
  • Frontend: coerce missing keys to empty arrays before passing to Chart.js:

    const labels   = Array.isArray(resp?.labels)   ? resp.labels   : [];
    const datasets = Array.isArray(resp?.datasets) ? resp.datasets : [];
    if (datasets.length) { /* build chart */ } else { /* show empty state */ }

Actual Behavior

Actual Behavior

  • Console shows errors like:

    chart.js:13 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    ...
    pmsChart.js:60 objectiveStatusDataUpdate
    pmsChart.js:159 keyResultStatusDataUpdate
    pmsChart.js:243 feedbackStatusDataUpdate
    
  • Example endpoint returns 200 with message-only JSON:

    • GET /pms/dashboard-feedback-status

    • Content-Type: application/json

    • Body:

      {"message": "No records available at the moment."}

Screenshots

No response

Django Version

na

Python Version

3.12

Operating System

Ubuntu 24.04

Browser

No response

Additional Information

No response

Possible Solution

No response

Labels

bug

Priority

Medium

Assignees

No response

Related Issues

No response

Submission Checklist

  • I have searched for duplicate issues
  • I have provided as much detail as possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions