Skip to content

get() returned more than one FormModelData #31

Open
@dcale

Description

I keep getting this error if I submit a form more than once:

MultipleObjectsReturned at /form/test/done/
get() returned more than one FormModelData -- it returned 11!

The issue happens because of the following code:

       try:
            display_key = self.request.GET.get('display_key')
            data = FormModelData.objects.get(display_key=display_key)
            context.update({
                'data': data,
            })
        except FormModelData.DoesNotExist:
            pass

The issue is fixed if one uses FormModelData.objects.filter(display_key=display_key).all()[0]. But this feels more like a hotfix/hack, because the issue lies deeper, you expect that display_key is unique, which is not the case if the same guy submits twice.

The other fix would be to except all exception and simply pass...

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions