straight55b / app-engine-patch

Automatically exported from code.google.com/p/app-engine-patch
0 stars 0 forks source link

Admin inline is broken #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Have models like these:
class PressItem(db.Model):
    pass

class File(db.Model)
    owner = db.ReferenceProperty(PressItem, required=True)
    name = db.StringProperty(required=True)
    file = db.BlobProperty(required=True)
    ...

2. forms like these:
class PressItemForm(forms.ModelForm):
    pass

class FileForm(forms.ModelForm):
    name = forms.CharField(required=False, label='Name')

3. admin like these:

class FileInline(admin.TabularInline):
    model = models.File
    form = forms.FileForm
    template = 'myapp/custom_template.html'
    extra = 1
    fields = ('name', 'file',)

class PressItemAdmin(UserVisibleAdmin):
    form = forms.PressItemForm    
    inlines = (FileInline,)

What is the expected output? What do you see instead?
Worked as expected with previous AEP code. Now I get

ERROR   02:37:47,180] signals.py:9 - Exception in request:
Traceback (most recent call last):
  File ".../django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File ".../django/contrib/admin/sites.py", line 490, in root
    return self.model_page(request, *url.split('/', 2))
  File ".../django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File ".../django/contrib/admin/sites.py", line 509, in model_page
    return admin_obj(request, rest_of_url)
  File ".../django/contrib/admin/options.py", line 1093, in __call__
    return self.add_view(request)
  File ".../django/contrib/admin/options.py", line 765, in add_view
    formset = FormSet(prefix=prefix)
  File ".../django/forms/models.py", line 684, in __init__
    queryset=qs)
  File ".../django/forms/models.py", line 448, in __init__
    super(BaseModelFormSet, self).__init__(**defaults)
  File ".../django/forms/formsets.py", line 44, in __init__
    self._construct_forms()
  File ".../django/forms/formsets.py", line 88, in _construct_forms
    self.forms.append(self._construct_form(i))
  File ".../django/forms/models.py", line 697, in _construct_form
    form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
  File ".../django/forms/models.py", line 472, in _construct_form
    return super(BaseModelFormSet, self)._construct_form(i, **kwargs)
  File ".../django/forms/formsets.py", line 108, in _construct_form
    self.add_fields(form, i)
  File ".../django/forms/models.py", line 718, in add_fields
    form.fields[self.rel_name] = InlineForeignKeyField(self.instance,
label=form.fields[self.rel_name].label)
KeyError: 'owner'

As you see I unzipped django zip to debug it. There is no 'fields' field in
the 'form' object at the moment add_fields is invoked (__init__ stack).

What version of the product are you using? On what operating system?
r161:65a93d9e52c4 (tip) of AEP-sample

Please provide any additional information below.
chunk of code

    if fields is not None:
        fields = list(fields)
        fields.append(fk.name)
    else:
        # get all the fields for this model that will be generated.
        fields = fields_for_model(model, fields, exclude,
formfield_callback).keys()
        fields.append(fk.name)

is now missing from django.forms.models.inlineformset_factory. Could it be
the exception reason? Trying to find a workaround now...

Original issue reported on code.google.com by A.A.Vasi...@gmail.com on 2 Aug 2009 at 8:47

GoogleCodeExporter commented 9 years ago
correction: there are
'DELETE', 'file', 'key', 'name',
in form.fields, but no 'owner'

Original comment by A.A.Vasi...@gmail.com on 2 Aug 2009 at 9:37

GoogleCodeExporter commented 9 years ago
Hmm, I saw 'owner', but not 'key' in my tracebacks. I've fixed this and several 
other 
issues, now. Please test again. The repo now contains Django 1.1 stable. The 
Django 
team changed a lot of internals, so it wasn't easy to merge everything and fix 
all 
bugs.

Original comment by wkornew...@gmail.com on 2 Aug 2009 at 1:48

GoogleCodeExporter commented 9 years ago
After update:

ERROR   09:04:04,160] signals.py:9 - Exception in request:
Traceback (most recent call last):
  File ".../django/core/handlers/base.py", line 92, in get_response
  File ".../django/contrib/admin/sites.py", line 490, in root
  File ".../django/views/decorators/cache.py", line 44, in _wrapped_view_func
  File ".../django/contrib/admin/sites.py", line 509, in model_page
  File ".../django/contrib/admin/options.py", line 1093, in __call__
  File ".../django/contrib/admin/options.py", line 765, in add_view
  File ".../django/forms/models.py", line 684, in __init__
  File ".../django/forms/models.py", line 448, in __init__
  File ".../django/forms/formsets.py", line 44, in __init__
  File ".../django/forms/formsets.py", line 88, in _construct_forms
  File ".../django/forms/models.py", line 697, in _construct_form
  File ".../django/forms/models.py", line 472, in _construct_form
  File ".../django/forms/formsets.py", line 108, in _construct_form
  File ".../django/forms/models.py", line 718, in add_fields
KeyError: 'owner'

trace output changed a bit...

Original comment by A.A.Vasi...@gmail.com on 2 Aug 2009 at 2:07

GoogleCodeExporter commented 9 years ago
Did you try to add "owner" to your FileInline?

Original comment by wkornew...@gmail.com on 2 Aug 2009 at 2:15

GoogleCodeExporter commented 9 years ago
BTW, the change you mentioned was done in Django:
http://code.djangoproject.com/changeset/10619

Original comment by wkornew...@gmail.com on 2 Aug 2009 at 2:25

GoogleCodeExporter commented 9 years ago
I added back a few lines from old django archive and this fixed code for me

Original comment by A.A.Vasi...@gmail.com on 2 Aug 2009 at 2:28

Attachments:

GoogleCodeExporter commented 9 years ago
Yes, adding 'owner' into fields also works

Original comment by A.A.Vasi...@gmail.com on 2 Aug 2009 at 2:50

GoogleCodeExporter commented 9 years ago
OK, then, I won't commit your patch because the respective code got removed 
from Django 
and aep should mimic Django as much as possible.

Original comment by wkornew...@gmail.com on 2 Aug 2009 at 3:09

GoogleCodeExporter commented 9 years ago
This is OK for me also. Thanks for the hint.

Original comment by A.A.Vasi...@gmail.com on 2 Aug 2009 at 3:26