simonw / datasette-leaflet-geojson

Datasette plugin that replaces any GeoJSON column values with a Leaflet map.
17 stars 7 forks source link

500 Error: TypeError unhashable type: 'dict' #24

Closed simonw closed 2 months ago

simonw commented 2 months ago

Just got this error on a table page that didn't hold any GeoJSON. I think it's because that table has a properties column containing JSON that isn't a fit for GeoJSON.

Table schema (from datasette-extract):

CREATE TABLE [_datasette_extract] (
   [id] TEXT PRIMARY KEY,
   [database_name] TEXT,
   [table_name] TEXT,
   [created] TEXT,
   [properties] TEXT,
   [completed] TEXT,
   [error] TEXT,
   [num_items] INTEGER
, [instructions] TEXT)

Example record:

{
    "id": "01HRCSG2XC60AK6E3PNRFBJ1RX",
    "database_name": "data",
    "table_name": "new_york_state_rfps",
    "created": "2024-03-07 15:46:18",
    "properties": "{\"award_number\": {\"type\": \"integer\"}, \"group\": {\"type\": \"integer\"}, \"award_title\": {\"type\": \"string\"}, \"type\": {\"type\": \"string\"}, \"keywords\": {\"type\": \"string\"}}",
    "completed": "2024-03-07 15:46:37",
    "error": "table new_york_state_rfps has no column named group...,",
    "num_items": 7,
    "instructions": null
}
simonw commented 2 months ago

Here's the Sentry error:

CleanShot 2024-04-24 at 21 42 11@2x

Relevant code: https://github.com/simonw/datasette-leaflet-geojson/blob/829e97ffd84ee1d917d0c6bf0f50aa5e321a97e8/datasette_leaflet_geojson/__init__.py#L30-L32

simonw commented 2 months ago

Minimum test that triggers the bug:

def test_render_cell_not_confused_by_other_properties():
    # https://github.com/simonw/datasette-leaflet-geojson/issues/24
    value = json.dumps(
        {
            "type": {"type": "string"},
        }
    )
    actual = render_cell(value)