super() argument 1 must be type, not None

781 views
Skip to first unread message

TiNo

unread,
Dec 21, 2009, 6:17:11 PM12/21/09
to django-users
Hi,

I am overriding a save function of a model with the following code:

    def save(self, *args, **kwargs):
        if (not self.id) and self.email != '':
            self.create_user()
        if hasattr(self, 'user'):
            self.user.email = self.email
            self.user.first_name = self.voornaam
            self.user.last_name = " ".join((self.tussenvoegsel, self.achternaam))
            self.user.save()
        super(Lid, self).save(*args, **kwargs)

where Lid is the name of the Model. However, for some reason it throws the following error since a while (don't know since when, don't know what changed, can't find anything suspicious in hg log...) "super() argument 1 must be type, not None". When I run with pdb.set_trace as the first line of the save method in the dev server, I can see that Lid is indeed None. What is surprising is that ALL my imports are None (User, datetime, models, etc.). I vaguely remember encountering this error before, but I don't remember what I did to fix it. What could have overridden all those things with None?

Does anybody have any clues? I can post my whole models.py if necessary, but it's rather large.

Thanks,

Tino

Kieran Brownlees

unread,
Dec 21, 2009, 6:19:48 PM12/21/09
to Django users
Have you restarted your server lately? I find that bug turns up from
time to time when the auto reloader doesn't reload properly.

Kieran

TiNo

unread,
Dec 21, 2009, 6:23:34 PM12/21/09
to django...@googlegroups.com
On Tue, Dec 22, 2009 at 00:19, Kieran Brownlees <kbrow...@gmail.com> wrote:
Have you restarted your server lately? I find that bug turns up from
time to time when the auto reloader doesn't reload properly.

Yep. Also tried in the dev server as mentioned...

TiNo

unread,
Dec 23, 2009, 10:41:36 AM12/23/09
to django...@googlegroups.com
I am overriding a save function of a model with the following code:

    def save(self, *args, **kwargs):
        if (not self.id) and self.email != '':
            self.create_user()
        if hasattr(self, 'user'):
            self.user.email = self.email
            self.user.first_name = self.voornaam
            self.user.last_name = " ".join((self.tussenvoegsel, self.achternaam))
            self.user.save()
        super(Lid, self).save(*args, **kwargs)

where Lid is the name of the Model. However, for some reason it throws the following error since a while (don't know since when, don't know what changed, can't find anything suspicious in hg log...) "super() argument 1 must be type, not None". When I run with pdb.set_trace as the first line of the save method in the dev server, I can see that Lid is indeed None. What is surprising is that ALL my imports are None (User, datetime, models, etc.). I vaguely remember encountering this error before, but I don't remember what I did to fix it. What could have overridden all those things with None?

Does anybody have any clues? I can post my whole models.py if necessary, but it's rather large.

Nobody any idea? It is quite frustrating as I have no way to further debug this.... 

Bill Freeman

unread,
Dec 23, 2009, 10:53:23 AM12/23/09
to django...@googlegroups.com
Are you sure that Lid is defined in this context? Try putting:

import pdb;pdb.set_trace()

before the super and check.

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

TiNo

unread,
Dec 23, 2009, 11:15:38 AM12/23/09
to django...@googlegroups.com
On Wed, Dec 23, 2009 at 16:53, Bill Freeman <ke1...@gmail.com> wrote:
Are you sure that Lid is defined in this context?  Try putting:

import pdb;pdb.set_trace()

before the super and check.

As I described, I checked that. The strange thing is, that it is defined as ``None``. As are all other imports, as ``datetime``, ``from django.db import models``. All these imported libraries and classes, as well as classes defined in that file are None for some reason. Quite weird...  

Doug Blank

unread,
Dec 23, 2009, 11:31:55 AM12/23/09
to django...@googlegroups.com

Perhaps this is a cyclic Python import issue. I think Python will go
through a file twice, the first time getting names into the scope, and
then a second time to fill in the details. Perhaps you are still in
the middle of importing when you are attempting to use the partially
loaded items.

Another way of looking at this is that an import statement is
atomic... no code will (should) run until all imports have completed,
then the code runs. I would try importing just some parts, or maybe
changing the import order.

Just some ideas. Good luck!

-Doug

Hanne Moa

unread,
Dec 23, 2009, 12:38:25 PM12/23/09
to django...@googlegroups.com
2009/12/22 TiNo <tin...@gmail.com>:
> /../ for some reason it throws the

> following error since a while (don't know since when, don't know what
> changed, can't find anything suspicious in hg log...) "super() argument 1
> must be type, not None". When I run with pdb.set_trace as the first line of
> the save method in the dev server, I can see that Lid is indeed None. What
> is surprising is that ALL my imports are None (User, datetime, models,
> etc.). I vaguely remember encountering this error before, but I don't
> remember what I did to fix it.

I have no idea how to fix it but I might have seen a similar problem;
Have you inspected globals()? What happened to me was that the
imported names existed in globals but they all pointed to None, hence,
useless. I could reimport something in the scope it were to be used,
but a function couldn't see other functions/symbols in the same
module!


HM

TiNo

unread,
Dec 23, 2009, 5:53:34 PM12/23/09
to django...@googlegroups.com
On Wed, Dec 23, 2009 at 17:31, Doug Blank <doug....@gmail.com> wrote:
Perhaps this is a cyclic Python import issue. I think Python will go
through a file twice, the first time getting names into the scope, and
then a second time to fill in the details. Perhaps you are still in
the middle of importing when you are attempting to use the partially
loaded items.

It was indeed a cyclic import. I finally found an import statement way below, where I imported a model recursively to add within a signal. Once I passed the required Model as a string to the signal connector and removed the input, everything worked again.

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages