Skip to content

GeoJsonTooltip / GeoJsonPopup crash on a single Feature or null properties #2345

Closed

Description

@kavyalavti

GeoJson accepts a single Feature or a bare geometry as data, but adding a GeoJsonTooltip or GeoJsonPopup to such a layer crashes at render time. A feature whose properties is null, which RFC 7946 allows, crashes too.

Minimal reproduction

import folium

m = folium.Map()
feature = {
    "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [0, 0]},
    "properties": {"name": "A"},
}
folium.GeoJson(feature, tooltip=folium.GeoJsonTooltip(fields=["name"])).add_to(m)
m.get_root().render()

Actual behavior

  File ".../folium/features.py", line 1216, in render
    self._parent.data["features"][0]["properties"].keys()
KeyError: 'features'

With "properties": None in a FeatureCollection, the same line raises AttributeError: 'NoneType' object has no attribute 'keys'.

Expected behavior

The tooltip or popup renders, as it does when the same feature is wrapped in a FeatureCollection. For a feature with no properties, or a bare geometry, any requested field is reported with the existing "The field ... is not available" message.

Cause

GeoJson only converts data to a FeatureCollection when style_function or highlight_function is given. GeoJsonDetail.render and warn_for_geometry_collections always read data["features"], and assume the first feature's properties is a dict. TopoJson had the same kind of problem with non-collection geometries, which was fixed earlier (test_topojson_non_collection_geometry_detail).

Environment

  • folium: main (aa7a23e)
  • Python 3.12.5, macOS

Activity

  1. added a commit that references this issue on Nov 15, 2026
    39854c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions