AttributeError 'tuple' object has no attribute '_meta'

Raised by:

django/forms/models.py (line 84)

Traceback (most recent call last):
  File "python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "python3.5/site-packages/braces/views/_access.py", line 98, in dispatch
    request, *args, **kwargs)
  File "python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "python3.5/site-packages/django/views/generic/edit.py", line 275, in get
    return super(BaseUpdateView, self).get(request, *args, **kwargs)
  File "python3.5/site-packages/django/views/generic/edit.py", line 213, in get
    return self.render_to_response(self.get_context_data())
  File "python3.5/site-packages/django/views/generic/edit.py", line 122, in get_context_data
    kwargs['form'] = self.get_form()
  File "python3.5/site-packages/django/views/generic/edit.py", line 74, in get_form
    return form_class(**self.get_form_kwargs())
  File "python3.5/site-packages/django/forms/models.py", line 282, in __init__
    object_data = model_to_dict(instance, opts.fields, opts.exclude)
  File "python3.5/site-packages/django/forms/models.py", line 84, in model_to_dict
    opts = instance._meta
AttributeError: 'tuple' object has no attribute '_meta'

How to reproduce

Return a tuple in the get_object method from a generic view:

def get_object(self):
    return MyModel.objects.get_or_create(
        name='some_name', user=self.request.user)

How to fix

Return only the instance and not a tuple:

def get_object(self):
    instance, _ MyModel.objects.get_or_create(
        name='some_name', user=self.request.user)
    return instance