google-code-export / django-treemenus

Automatically exported from code.google.com/p/django-treemenus
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Extending Menu Items breaks some unit tests #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As per subject line. We get errors such as:

======================================================================
ERROR: test_view_add_item (treemenus.tests.TreemenusTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/richard/workspace/sameeraSN/treemenus/tests.py", line 50, in
test_view_add_item
    response =
self.client.post('/test_treemenus_admin/treemenus/menu/%s/items/add/' %
menu.pk, menu_item_data)
  File "/sw/lib/python2.5/site-packages/django/test/client.py", line 313,
in post
    response = self.request(**r)
  File "/sw/lib/python2.5/site-packages/django/core/handlers/base.py", line
92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/sw/lib/python2.5/site-packages/django/views/decorators/cache.py",
line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/sw/lib/python2.5/site-packages/django/contrib/admin/sites.py",
line 186, in inner
    return view(request, *args, **kwargs)
  File "/Users/richard/workspace/sameeraSN/treemenus/admin.py", line 128,
in add_menu_item
    return menuitem_admin.add_view(request, extra_context={ 'menu': menu })
  File "/sw/lib/python2.5/site-packages/django/db/transaction.py", line
240, in _commit_on_success
    res = func(*args, **kw)
  File "/sw/lib/python2.5/site-packages/django/contrib/admin/options.py",
line 731, in add_view
    prefix=prefix)
  File "/sw/lib/python2.5/site-packages/django/forms/models.py", line 724,
in __init__
    queryset=qs)
  File "/sw/lib/python2.5/site-packages/django/forms/models.py", line 459,
in __init__
    super(BaseModelFormSet, self).__init__(**defaults)
  File "/sw/lib/python2.5/site-packages/django/forms/formsets.py", line 44,
in __init__
    self._construct_forms()
  File "/sw/lib/python2.5/site-packages/django/forms/formsets.py", line 87,
in _construct_forms
    for i in xrange(self.total_form_count()):
  File "/sw/lib/python2.5/site-packages/django/forms/models.py", line 734,
in total_form_count
    return super(BaseInlineFormSet, self).total_form_count()
  File "/sw/lib/python2.5/site-packages/django/forms/formsets.py", line 66,
in total_form_count
    return self.management_form.cleaned_data[TOTAL_FORM_COUNT]
  File "/sw/lib/python2.5/site-packages/django/forms/formsets.py", line 54,
in _management_form
    raise ValidationError('ManagementForm data is missing or has been
tampered with')
ValidationError: [u'ManagementForm data is missing or has been tampered with']

----------------------------------------------------------------------

To be precise, the problem only occurs if you've extended the model AND
added a new admin to manage it.
I've attached a patch with a very simple fix: it skips the troublesome
tests if the model has been extended. It "feels" to me like a bit of a
hack, I can't think of a better solution at the moment but there probably
is one!

Original issue reported on code.google.com by richardb...@gmail.com on 4 Oct 2009 at 8:22

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report Richard, but I cannot reproduce this bug. In r55 I have
restructured the tests to try to reproduce the conditions you described, but 
all the
tests still pass.

I'm closing as invalid. But if you still have problems with that, please 
re-open this
ticket with a precise description of how to reproduce this bug. Thank you.

Original comment by jpha...@gmail.com on 6 Dec 2009 at 5:40

GoogleCodeExporter commented 9 years ago
Hi again,

I've dug deeper into this bug to find the exact condition that reproduces it.
Attached to this post is a diff that creates a new app called 'temp'; this is
basically a copy-and-paste of the example code from MANUAL.txt.
It creates a new model AND the admin to go with it.

If you plug this example app into a project (and add it to INSTALLED_APPS) you 
should
be able to reproduce the bug... hopefully!

I've found that the source of the bug is the line "inlines =
[MenuItemExtensionInline,]", although I don't know *why* it's a problem :-(

Original comment by richardb...@gmail.com on 9 Dec 2009 at 3:57

Attachments:

GoogleCodeExporter commented 9 years ago
I think it should be fixed in r58. Try again with the latest development 
version and
see if that fixes your problem. Thanks!

Original comment by jpha...@gmail.com on 12 Dec 2009 at 9:08

GoogleCodeExporter commented 9 years ago
Hi again,
Tried r58 but it has not fixed the problem. Sorry :-(

Original comment by richardb...@gmail.com on 14 Dec 2009 at 12:26

GoogleCodeExporter commented 9 years ago
Ok, I'm reopening. I'll take a look at it when I find the time. Thanks.

Original comment by jpha...@gmail.com on 14 Dec 2009 at 8:35

GoogleCodeExporter commented 9 years ago
Yes, I could reproduce the issue. The problem is that the tests we written with 
the assumption there wouldn't be any extension inlines. I'm not sure exactly 
how to fix this, but I'll keep investigating. Any suggestion would be welcome. 
BTW, the project is now on github: http://github.com/jphalip/django-treemenus

Thanks!

Original comment by jpha...@gmail.com on 9 Oct 2010 at 2:04