Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

afterInit called twice + errors in it not caught (breaks compat.) #34

@erikkaplun

Description

@erikkaplun

(I will describe both the issue and the solution here because I already have a patch for this)

After I added a call to afterInit in DBObject.__init__, it (now obviously) started to be called twice: once per createinstances and once per __init__. So I wanted to remove the call to afterInit in createInstances. Seeing the code in createInstances though made me realise that my added line in __init__ swallows errors in afterInit. But afterInit needs to be asynchronous (if not for any practical pruposes—but there are—as per the doc, at least), which means it cannot really be called from __init__ because __init__ is not allowed to return anything (and thus not allowed to return a Deferred). However, __new__ does not suffer from this limitation. So the end solution is to put the call to afterInit into DBObject.__new__.

As a bonus, I also updated the usage of DeferredList in createInstances to include fireOnFirstErrback=True, consumeErrors=True so that any exceptions wouldn't go unnoticed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions