#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 )
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)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 9 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 , 9 years ago
| Component: | Forms → GIS |
|---|---|
| Severity: | Normal → Release blocker |
| Summary: | KeyError 'widget' in BaseGeometryWidget → BaseGeometryWidget.subwidgets() crashes with KeyError 'widget' |
| Triage Stage: | Unreviewed → Accepted |
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
follow-up: 5 comment:4 by , 9 years ago
| Description: | modified (diff) |
|---|---|
| Has patch: | set |
Dariusz, could you your application with this PR. I'm not certain that it's correct.
comment:5 by , 9 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, 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.
Can you provide a test case to reproduce the issue?