#14283: AttributeError on admin detail page after r13708
----------------------------------------------+-----------------------------
          Reporter:  rene.p...@repro-mayr.de  |         Owner:  nobody
            Status:  new                      |     Milestone:        
         Component:  Uncategorized            |       Version:  1.2   
        Resolution:                           |      Keywords:        
             Stage:  Unreviewed               |     Has_patch:  0     
        Needs_docs:  0                        |   Needs_tests:  0     
Needs_better_patch:  0                        |  
----------------------------------------------+-----------------------------
Comment (by rene.p...@repro-mayr.de):

 I have spent some more time tracking down this problem. Here is what I
 have found out.

 There are three model classes involved:

  * Model A, no fields required
  * Model B, no fields required
  * Model C, with a generic foreign key and a regular foreign key to model
 B

 And there are also two admin classes involved:

  * ModelCInline, a !GenericTabularInline for model C
  * ModelAAdmin, which includes ModelCInline
  * In addition, model B must be registered with the admin site, but does
 not need any special options

 When I try to add or change instances of model A on the admin site, I get
 an !AttributeError with the following traceback:

 {{{
 Environment:

 Request Method: GET
 Request URL: http://localhost:8000/admin/testapp/modela/add/
 Django Version: 1.3 pre-alpha SVN-13865
 Python Version: 2.7.0
 Installed Applications:
 ['django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.sites',
  'django.contrib.messages',
  'django.contrib.admin',
  'testcase14283.testapp']
 Installed Middleware:
 ('django.middleware.common.CommonMiddleware',
  'django.contrib.sessions.middleware.SessionMiddleware',
  'django.middleware.csrf.CsrfViewMiddleware',
  'django.contrib.auth.middleware.AuthenticationMiddleware',
  'django.contrib.messages.middleware.MessageMiddleware')


 Traceback:
 File "/Users/rpuls/Library/Python/django/core/handlers/base.py" in
 get_response
   100.                     response = callback(request, *callback_args,
 **callback_kwargs)
 File "/Users/rpuls/Library/Python/django/contrib/admin/options.py" in
 wrapper
   245.                 return self.admin_site.admin_view(view)(*args,
 **kwargs)
 File "/Users/rpuls/Library/Python/django/utils/decorators.py" in
 _wrapped_view
   76.                     response = view_func(request, *args, **kwargs)
 File "/Users/rpuls/Library/Python/django/views/decorators/cache.py" in
 _wrapped_view_func
   78.         response = view_func(request, *args, **kwargs)
 File "/Users/rpuls/Library/Python/django/contrib/admin/sites.py" in inner
   190.             return view(request, *args, **kwargs)
 File "/Users/rpuls/Library/Python/django/utils/decorators.py" in _wrapper
   21.             return decorator(bound_func)(*args, **kwargs)
 File "/Users/rpuls/Library/Python/django/utils/decorators.py" in
 _wrapped_view
   76.                     response = view_func(request, *args, **kwargs)
 File "/Users/rpuls/Library/Python/django/utils/decorators.py" in
 bound_func
   17.                 return func(self, *args2, **kwargs2)
 File "/Users/rpuls/Library/Python/django/db/transaction.py" in
 _commit_on_success
   299.                     res = func(*args, **kw)
 File "/Users/rpuls/Library/Python/django/contrib/admin/options.py" in
 add_view
   822.                                        self.inline_instances):
 File "/Users/rpuls/Library/Python/django/contrib/admin/options.py" in
 get_formsets
   421.             yield inline.get_formset(request, obj)
 File "/Users/rpuls/Library/Python/django/contrib/contenttypes/generic.py"
 in get_formset
   403.         return generic_inlineformset_factory(self.model,
 **defaults)
 File "/Users/rpuls/Library/Python/django/contrib/contenttypes/generic.py"
 in generic_inlineformset_factory
   369.                                    fields=fields, exclude=exclude,
 max_num=max_num)
 File "/Users/rpuls/Library/Python/django/forms/models.py" in
 modelformset_factory
   685.                              formfield_callback=formfield_callback)
 File "/Users/rpuls/Library/Python/django/forms/models.py" in
 modelform_factory
   423.     return ModelFormMetaclass(class_name, (form,),
 form_class_attrs)
 File "/Users/rpuls/Library/Python/django/forms/models.py" in __new__
   227.                                       opts.exclude, opts.widgets,
 formfield_callback)
 File "/Users/rpuls/Library/Python/django/forms/models.py" in
 fields_for_model
   185.             formfield = formfield_callback(f, **kwargs)
 File "/Users/rpuls/Library/Python/django/contrib/admin/options.py" in
 formfield_for_dbfield
   113.
 related_modeladmin.has_add_permission(request))
 File "/Users/rpuls/Library/Python/django/contrib/admin/options.py" in
 has_add_permission
   292.         return request.user.has_perm(opts.app_label + '.' +
 opts.get_add_permission())

 Exception Type: AttributeError at /admin/testapp/modela/add/
 Exception Value: 'NoneType' object has no attribute 'user'
 }}}

 One interesting thing is that the error goes away as soon as I remove the
 line that registers model B with the admin site.

 For a minimal test case, you can use the attached project, which is
 basically just a models.py:

 {{{
 #!python
 import django.db.models as dj_models
 import django.contrib.admin as dj_admin
 import django.contrib.contenttypes.models as dj_ct_models
 import django.contrib.contenttypes.generic as dj_generic


 # model classes

 class ModelC(dj_models.Model):
     relation_b = dj_models.ForeignKey('ModelB')

     tagged_object = dj_generic.GenericForeignKey()
     content_type = dj_models.ForeignKey(dj_ct_models.ContentType)
     object_id = dj_models.PositiveIntegerField()


 class ModelA(dj_models.Model):
     pass


 class ModelB(dj_models.Model):
     pass


 # admin classes

 class ModelCInline(dj_generic.GenericTabularInline):
     model = ModelC


 class ModelAAdmin(dj_admin.ModelAdmin):
     inlines = [ModelCInline]


 dj_admin.site.register(ModelA, ModelAAdmin)

 # remove the following line to make the error go away
 dj_admin.site.register(ModelB)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14283#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to