willhardy/django-seo

Exception when running under pydev debugger

Closed this issue · 7 comments

Hi,

I have an error saying "TypeError: 'class Meta' got invalid attribute(s): self,options" when launching my project in debugger (I use pydev debugger). In normal mode (without debugger) this error does not occur. Traceback shows also some dependency with django-cms publisher.

Here's the tracebkack fragment:

 File "ProjectPath\main\seo.py", line 4, in <module>
 class SEOMetadata(seo.Metadata):
 File "build\bdist.win32\egg\rollyourown\seo\base.py", line 200, in __new__
 File "build\bdist.win32\egg\rollyourown\seo\options.py", line 69, in _add_backend
 File "build\bdist.win32\egg\rollyourown\seo\backends.py", line 161, in get_model
 File "c:\python25\lib\site-packages\django_cms-2.1.0.rc1-py2.5.egg\publisher\base.py",   line 50, in publisher_modelbase_new
new_class = _old_new(cls, name, bases, attrs)
File "C:\Python25\lib\site-packages\django\db\models\base.py", line 53, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python25\lib\site-packages\django\db\models\base.py", line 213, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python25\lib\site-packages\django\db\models\options.py", line 93, in contribute_to_class
raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()))
TypeError: 'class Meta' got invalid attribute(s): self,options

Do you have any ideas?

This sounds like django_cms is doing some interesting black magic here. The two variables (self and options) are global variables when creating the models used to store metadata. Each model class creates a closure over these variables, so I have no idea why they would be appearing again.

I'll have a look at what django_cms is doing, I assume it takes over class creation, but I'll have another look. The developers were probably working on the assumption that django models haven't been created this way.

Are you able to send some more information (ie, your seo.py file)?

Thanks for fast response.
I'll also make some investigation on django_cms magic in the morning and let you know if I'll find anything interesting.

My seo.py file is quite simple, here it goes:

from rollyourown import seo


class SEOMetadata(seo.Metadata):
    title       = seo.Tag(head=True, max_length=68)
    description = seo.MetaTag(max_length=155)
    keywords    = seo.KeywordTag()

    class Meta:
        use_cache = True
        backends = ('path', 'modelinstance', 'model', 'view')
        verbose_name = "Dane SEO"
        verbose_name_plural = "SEO"

It is also interesting why this happens only when I use debugger...

That is a very simple file (note that backends is not required, the value you have used is the default), I have no idea what's going on. Perhaps someone is monkey patching or maybe there is something amis with the debugger.

Are you able to see the value of attrs when it reaches c:\python25\lib\site-packages\django_cms-2.1.0.rc1-py2.5.egg\publisher\base.py at line 50?

I made further investigation and I disabled django-cms and suprisingly problem remains. Looks like django-cms is innocent in this case.

End of traceback without cms looks like this:

  File "build\bdist.win32\egg\rollyourown\seo\backends.py", line 161, in get_model
  File "C:\Python25\lib\site-packages\django\db\models\base.py", line 53, in     __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "C:\Python25\lib\site-packages\django\db\models\base.py", line 213, in add_to_class
value.contribute_to_class(cls, name)
  File "C:\Python25\lib\site-packages\django\db\models\options.py", line 93, in contribute_to_class
  raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()))

Ok, I went and installed pydev --- not particularly enjoyable for a non IDE person such as me :-( and run it in debug. I noticed that it tried to launch psyco, which might be the actual cause of your problems.

Are you able to disable psyco? Is the exception gone?

Thanks for checking it out.

I've managed to disable psyco but the problem remains.

As I'm still not able to reproduce this, I'll close this ticket. Let me know if it's a problem for you, there might be ways around it, but I'd rather use a class as a closure than artificially create it using type().