Opened 19 months ago

Closed 18 months ago

Last modified 18 months ago

#28039 closed Bug (fixed)

BaseGeometryWidget.subwidgets() crashes with KeyError 'widget'

Reported by: Dariusz Paluch Owned by: nobody
Component: GIS Version: 1.11
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

BaseGeometryWidget.get_context() doesn't execute super().get_context(self, name, value, attrs) so key 'widget' used by method subwidgets() doesn't exist.

Change History (7)

comment:1 Changed 19 months ago by Tim Graham

Can you provide a test case to reproduce the issue?

comment:2 in reply to:  1 Changed 19 months ago by Dariusz Paluch

Replying to Tim Graham:

Can you provide a test case to reproduce the issue?

Just use any BaseGeometryWidget based form field in form.

comment:3 Changed 19 months ago by Tim Graham

Component: FormsGIS
Severity: NormalRelease blocker
Summary: KeyError 'widget' in BaseGeometryWidgetBaseGeometryWidget.subwidgets() crashes with KeyError 'widget'
Triage Stage: UnreviewedAccepted

Here's a snippet to reproduce:

>>> from django.contrib.gis.forms import OpenLayersWidget
>>> widget = forms.OpenLayersWidget()
>>> list(widget.subwidgets('name', 'value'))
Traceback (most recent call last):
...
  File "django/django/forms/widgets.py", line 177, in subwidgets
    yield context['widget']
KeyError: 'widget

comment:4 Changed 19 months ago by Tim Graham

Description: modified (diff)
Has patch: set

Dariusz, could you your application with this PR. I'm not certain that it's correct.

comment:5 in reply to:  4 Changed 18 months ago by dpaluch-rp

Replying to Tim Graham:

Dariusz, could you your application with this PR. I'm not certain that it's correct.

I'm fixed my application the same way, so looks promise.

class GoogleMapWidget(forms.BaseGeometryWidget):

    map_width = 800
    map_height = 500
    template_name = 'gis/google.html'

    def serialize(self, value):
        return value.geojson if value else ''

    def get_context(self, name, value, attrs):
        # TODO: Bug Django 1.11, BaseGeometryWidget.get_context don't call super(), so context don't have "widget" key
        context = super().get_context(name, value, attrs)
        super_context = super(forms.BaseGeometryWidget, self).get_context(name, value, attrs)
        super_context.update(context)
        return super_context

Unfortunelly my apps is not django 2.0 ready because of GIS usage, so I can't test your commit.

Last edited 18 months ago by dpaluch-rp (previous) (diff)

comment:6 Changed 18 months ago by GitHub <noreply@…>

Resolution: fixed
Status: newclosed

In d2cb7a2b:

Fixed #28039 -- Fixed crash in BaseGeometryWidget.subwidgets().

comment:7 Changed 18 months ago by Tim Graham <timograham@…>

In 5e2bbcd7:

[1.11.x] Fixed #28039 -- Fixed crash in BaseGeometryWidget.subwidgets().

Backport of d2cb7a2bc11f111be04a29b5e4f92a183b18ba88 from master

Note: See TracTickets for help on using tickets.
Back to Top