Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Lead organisation for PDU paediatric_diabetes_unit.lead_organisation_ods_code='8HV48' not found #450

Closed
anchit-chandran opened this issue Dec 30, 2024 · 2 comments · Fixed by #454
Assignees
Labels
bug Something isn't working

Comments

@anchit-chandran
Copy link
Contributor

Getting this on local development, can look into once finished other work:

django-1   | ERROR [django.request] Internal Server Error: /get_map_chart_partial
django-1   | Traceback (most recent call last):
django-1   |   File "/app/project/npda/views/dashboard/partials.py", line 201, in get_map_chart_partial
django-1   |     pdu_lead_organisation = fetch_organisation_by_ods_code(
django-1   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   | KeyError: 'properties'
caddy-1    | {"level":"error","ts":1735560120.6741333,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"192.168.65.1","remote_port":"40775","client_ip":"192.168.65.1","proto":"HTTP/2.0","method":"GET","host":"npda.localhost","uri":"/get_map_chart_partial","headers":{"Sec-Fetch-Mode":["cors"],"Referer":["https://npda.localhost/dashboard"],"Cookie":["REDACTED"],"Hx-Current-Url":["https://npda.localhost/dashboard"],"Accept":["*/*"],"Hx-Target":["organisation_cases_map"],"Sec-Fetch-Dest":["empty"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Sec-Ch-Ua-Mobile":["?0"],"Hx-Request":["true"],"Sec-Fetch-Site":["same-origin"],"Priority":["u=1, i"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Ch-Ua":["\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\""]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"npda.localhost"}},"bytes_read":0,"user_id":"","duration":0.499956417,"size":86917,"status":500,"resp_headers":{"Date":["Mon, 30 Dec 2024 12:02:00 GMT"],"Cross-Origin-Opener-Policy":["same-origin"],"X-Frame-Options":["DENY"],"X-Content-Type-Options":["nosniff"],"Referrer-Policy":["same-origin"],"Content-Type":["text/html; charset=utf-8"],"Content-Length":["86917"],"Vary":["Cookie"],"Server":["Caddy","WSGIServer/0.2 CPython/3.12.8"],"Alt-Svc":["h3=\":443\"; ma=2592000"]}}
django-1   | 
django-1   | During handling of the above exception, another exception occurred:
django-1   | 
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 "/app/project/npda/views/decorators.py", line 56, in sync_login_and_otp_required
django-1   |     return view(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/project/npda/views/dashboard/partials.py", line 205, in get_map_chart_partial
django-1   |     raise ValueError(
django-1   | ValueError: Lead organisation for PDU paediatric_diabetes_unit.lead_organisation_ods_code='8HV48' not found
django-1   | ERROR [django.server] "GET /get_map_chart_partial HTTP/1.1" 500 86917
@anchit-chandran anchit-chandran added the bug Something isn't working label Dec 30, 2024
@anchit-chandran
Copy link
Contributor Author

anchit-chandran commented Dec 31, 2024

@eatyourpeas narrowed this down to dashboard/partials.py::200 where we have

    try:
        pdu_lead_organisation = fetch_organisation_by_ods_code(
            ods_code=paediatric_diabetes_unit.lead_organisation_ods_code
        )["properties"]
    except:
        raise ValueError(
            f"Lead organisation for PDU {paediatric_diabetes_unit.lead_organisation_ods_code=} not found"
        )

Looks like fetch_organisation_by_ods_code doesn't have a properties attribute, unsure which other one maps to pdu_lead_organisation from (although the RCPCH organisation might be a bad example as not a 'real' org?):

'ods_code': '8HV48'
'name': 'ROYAL COLLEGE OF PAEDIATRICS AND CHILD HEALTH'
'website': 'https://www.rcpch.ac.uk/'
'address1': '5-11 Theobalds Road'
'address2': None
'address3': None
'telephone': '020 7092 6000'
'city': 'London'
'county': None
'latitude': 51.521
'longitude': -0.1184349
'postcode': 'WC1X 8SH'
'geocode_coordinates': {'type': 'Point', 'coordinates': [-0.1184349, 51.521]}
'active': True
'published_at': None
'local_authority_district': {'lad24cd': 'E09000007', 'lad24nm': 'Camden', 'lad24nmw': None, 'bng_e': 527491, 'bng_n': 184283, 'long': -0.16291, 'lat': 51.543}
'lower_layer_super_output_area': {'lsoa11cd': 'E01000914', 'lsoa11nm': 'Camden 028B', 'lsoa11nmw': 'Camden 028B', 'bng_e': 530733, 'bng_n': 181688, 'long': -0.11714, 'lat': 51.519}
'paediatric_diabetes_unit': {'pz_code': 'PZ999', 'paediatric_diabetes_network': None}
'trust': None
'local_health_board': None
'integrated_care_board': None
'nhs_england_region': None
'openuk_network': None
'london_borough': None
'country': None
len(): 25

@eatyourpeas
Copy link
Member

This is my fault sorry. Over the Xmas and lead up I did an overhaul of the RCPCH NHS Organisations API and created new endpoints for geojson to reduce the size of the objects returned. Although I thought I left this endpoint alone I must inadvertently changed the serializer - this object is much neater and smaller in any case. The properties element is part of the geojson object so that just needs removing from the API call and then it should work as before. I can do this - let me know if it is blocking any progress and I can prioritize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants