Tom Thorogood Tom Thorogood - 1 year ago 36
Python Question

Python super() behavior not dependable

For some reason, the

method is not always behaving as expected, opting to return:

TypeError('super(type, obj): obj must be an instance or subtype of type)'

I understand what the error means. I do not understand why it is coming up as an error. Here's the snippet of code that is breaking. All objects in the system are new style objects.

What's really interesting is that this error does not always show up. I don't know what's causing it. The
method in
is passing the
class, and then itself as an object, which is, as far as I'm aware,exactly how
is supposed to be invoked.

Any thoughts at all?

In file

class DBAdminConnection(object):
def __init__(self):
self.user = DBUserConnection().user
self.submissions = DBSubmissionConnection()

In file

class Retrieval(DBConnection.DBAdminConnection):
def __init__(self, username=None, password=None, unique_key=None):
if username and password:
self.username = username
self.user.login(username,password, config.DATABASE)
if self.user.error:
raise UserLoginError(username)
self.unique_key = unique_key

Answer Source

Are you reloading modules somehow in the middle of things? If so, that may explain this error.

isinstance(self,DBAdminConnection) may become false after reloading modules because of the changes to memory references, apparently.

Edit: if you're running your app under mod_wsgi, make sure you're disabling autoreload:

app = web.application(urls, globals(), autoreload=False)