Opened 8 years ago

Closed 8 years ago

Last modified 8 years 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 by Tim Graham, 8 years ago

Can you provide a test case to reproduce the issue?

in reply to:  1 comment:2 by Dariusz Paluch, 8 years ago

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 by Tim Graham, 8 years ago

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 by Tim Graham, 8 years ago

Description: modified (diff)
Has patch: set

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

in reply to:  4 comment:5 by dpaluch-rp, 8 years ago

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.

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
Version 1, edited 8 years ago by dpaluch-rp (previous) (next) (diff)

comment:6 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In d2cb7a2b:

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

comment:7 by Tim Graham <timograham@…>, 8 years ago

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