rcpch / national-paediatric-diabetes-audit

A django application to audit the care of children and young people with diabetes in England and Wales.
0 stars 1 forks source link

Crash on submissions page with CSV where NHS numbers have no spaces #357

Closed mbarton closed 2 weeks ago

mbarton commented 2 weeks ago
  1. Edit dummy_sheet.csv 1a. Remove all but the headings and first line 2b. Edit the NHS number to have no spaces
  2. Upload

You get a big 'ol crash rendering the submissions page:

django-1   | ERROR [django.request] Internal Server Error: /submissions
django-1   | Traceback (most recent call last):
django-1   |   File "/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
django-1   |     response = get_response(request)
django-1   |                ^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
django-1   |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
django-1   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
django-1   |     return self.dispatch(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/project/npda/views/mixins.py", line 41, in dispatch
django-1   |     return super().dispatch(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
django-1   |     return handler(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/project/npda/views/submissions.py", line 94, in get
django-1   |     context = self.get_context_data(object_list=self.object_list)
django-1   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/project/npda/views/submissions.py", line 79, in get_context_data
django-1   |     context["data"] = csv_summarize(latest_active_submission.csv_file)
django-1   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/project/npda/general_functions/csv_summarize.py", line 30, in csv_summarize
django-1   |     dataframe["NHS Number"].fillna("").apply(lambda x: x.replace(" ", "")).unique()
django-1   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/pandas/core/series.py", line 4924, in apply
django-1   |     ).apply()
django-1   |       ^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/pandas/core/apply.py", line 1427, in apply
django-1   |     return self.apply_standard()
django-1   |            ^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/pandas/core/apply.py", line 1507, in apply_standard
django-1   |     mapped = obj._map_values(
django-1   |              ^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/pandas/core/base.py", line 921, in _map_values
django-1   |     return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.12/site-packages/pandas/core/algorithms.py", line 1743, in map_array
django-1   |     return lib.map_infer(values, mapper, convert=convert)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "lib.pyx", line 2972, in pandas._libs.lib.map_infer
django-1   |   File "/app/project/npda/general_functions/csv_summarize.py", line 30, in <lambda>
django-1   |     dataframe["NHS Number"].fillna("").apply(lambda x: x.replace(" ", "")).unique()
django-1   |                                                        ^^^^^^^^^
django-1   | AttributeError: 'int' object has no attribute 'replace'
django-1   | ERROR [django.server] "GET /submissions HTTP/1.1" 500 126099