开发者

super() argument 1 must be type, not None

A class in one of my modules in my django application has a problem constructing itself using super...

class LinkshareExternalAffiliateProperties(AffiliateExternalProperties):

    def __init__(self, aggregator_affiliate_id, account_username, account_password, api_token):
        super(LinkshareExternalAffiliateProperties, self).__init__(aggregator_affiliate_id)
        self.account_username = account_username
        self.account_password = account_password
        self.api_token = api_token

class AffiliateExternalProperties(object):

    def __getattribute__(self, attr):
        sources = super(AffiliateExternalProperties, self).__getattribute__('__sources__')
        if attr in sources:
            return self.get(attr)
        else:
            return super(AffiliateExternalProperties, self).__getattribute__(attr)

When the code is called I get an error: super() argument 1 must be type, not None How does LinkshareExternalAffiliateProperties evaluate to None right here? Its the class of this new instance!! Other classes in the same module are also unavailable at this time.

SOME THINGS OF INTEREST (This whole thing is convoluted but some part of the whole story could be what is creating the problem...):

class Aggregator(models.Model):
    foo = columns

    @property
    def proxy(self):
        if self.name == 'Linkshare':
            return Linkshare.objects.get_instance()
        elif self.name == '开发者_开发百科Commission Junction':
            return CommissionJunction.objects.get_instance()
        elif self.name == 'Share-A-Sale':
            return ShareASale.objects.get_instance()
        else:
            raise Exception('Invalid aggregator name "%s".  Excpected Linkshare, Commission Junction, or Share-A-Sale.' % self.name)


class Linkshare(models.Model):

    def affiliate_properties(self, aggregator_affiliate_id):
        return LinkshareExternalAffiliateProperties(aggregator_affiliate_id, self.username, self.password)


class Affiliate(models.Model):
    foo = columns

    def get_external_properties():
        return self.aggregator.proxy.get_external_properties(self.aggregator_affiliate_id)

class MyView(self):

    def view(self, request):
        affiliate = get_object_or_404(Affiliate, pk=id)
        properties = affiliate.get_external_properties()
        return render_to_response('admin/affiliates/affiliate/affiliate_scrape_ajax.html', dict(scrape=properties))

Hitting /view in the browser raises the error...

The kicker, running this code LOCALLY it works just fine w/o raising the error.

When I run it using gunicorn & nginx, it messes up.


Check that you're not assigning over the class after you declare it. The following will cause the error you're seeing:

class foo(object):
    def x(self):
        print "foo"

class bar(foo):
    def x(self):
        super(bar, self).x()

baz = bar
bar = None

a = baz()
a.x()


Gunicorn has a bug:

django run_gunicorn + reload

one possibility to fix reload using Django 'un_gunicorn' command with manage.py would be to consider that reload == reexec. So we are making sure we reload all modules. But with this solution the process id will change and some supervisor may not be abble to detect the change if they aren't using the pidfile. (In other word we should strongly advise people to use gunicorn_django command if they want HUP support.)

https://github.com/benoitc/gunicorn/issues/222

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜