Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__init__() got an unexpected keyword argument 'instance' #22

Open
ArtemBernatskyy opened this issue May 26, 2017 · 9 comments
Open

__init__() got an unexpected keyword argument 'instance' #22

ArtemBernatskyy opened this issue May 26, 2017 · 9 comments

Comments

@ArtemBernatskyy
Copy link

ArtemBernatskyy commented May 26, 2017

Hello, i am using Django 1.10.7

And got this error

Traceback:

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  42.             response = get_response(request)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/braces/views/_access.py" in dispatch
  102.             request, *args, **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/braces/views/_access.py" in dispatch
  341.             request, *args, **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  213.         return super(BaseCreateView, self).get(request, *args, **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  174.         return self.render_to_response(self.get_context_data())

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/edit.py" in get_context_data
  93.             kwargs['form'] = self.get_form()

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/views/generic/edit.py" in get_form
  45.         return form_class(**self.get_form_kwargs())

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django_superform/forms.py" in __init__
  160.         self._init_composite_fields()

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django_superform/forms.py" in _init_composite_fields
  212.             self._init_composite_field(name, field)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django_superform/forms.py" in _init_composite_field
  195.             formset = field.get_formset(self, name)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django_superform/fields.py" in get_formset
  371.             **kwargs)

File "/var/webapps/mtas_proj/env/local/lib/python2.7/site-packages/django/forms/models.py" in __init__
  568.         super(BaseModelFormSet, self).__init__(**defaults)

Exception Type: TypeError at /collection-manager/add/
Exception Value: __init__() got an unexpected keyword argument 'instance'

forms.py

from django import forms

from django_superform import SuperModelForm, InlineFormSetField

from .models import (
    Site, AdvancedSearchFields
)


class AdvancedSearchFieldsForm(forms.ModelForm):
    class Meta:
        model = AdvancedSearchFields
        fields = ['site', 'advanced_search_url', 'name', 'xpath']


AdvancedSearchFieldsFormSet = forms.modelformset_factory(model=AdvancedSearchFields,form=AdvancedSearchFieldsForm)


class SiteCreateForm(SuperModelForm):
    advanced_search_fields = InlineFormSetField(formset_class=AdvancedSearchFieldsFormSet)

    class Meta(object):
        model = Site

        fields = (
            'name',
            'description',
            'base_url',
            'site_type',
            'collection_speed',
            'registraton_url',
            'logout_url',
            'updates_url',
            'check_for_updates'
        )

@ArtemBernatskyy
Copy link
Author

I will test if this resolves the issue.

@ArtemBernatskyy
Copy link
Author

Nope, it didn't work for me.

@ArtemBernatskyy
Copy link
Author

This also won't work .

@krriyo
Copy link

krriyo commented Jul 24, 2017

Looks like it is the way BaseModelFormSet handles kwargs. I'm trying to fix it, will let you know how that goes

@metemaddar
Copy link

The same in Django 1.11.5

@hendrikschneider
Copy link

Any news on this?

@kaliif
Copy link

kaliif commented Nov 14, 2018

Any news now? I can't keep removing **kwargs from init.

@kartoophilus
Copy link

So still no solution on this??????????????????

@jerebenitez
Copy link

Had this problem too. It happened because, on my form, I was inheriting from a custom ModelForm and from SuperModelForm. The solution ended up being inheriting from SuperModelFormMixin and my custom ModelForm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants