Open erikkaplun opened 11 years ago
(Ignore the first reference—I --force push
ed the updated commit so Github is redisplaying it)
The last commit provides backwards compatibility in most cases (i.e. when afterInit
does not return a Deferred
). The change as a whole does break it but then again—any code that was using afterInit
was by definition buggy anyway, unless it had some explicit workarounds, or the previous (inconsistent) behaviour was depended on or happened to not break anything.
(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
inDBObject.__init__
, it (now obviously) started to be called twice: once percreateinstances
and once per__init__
. So I wanted to remove the call toafterInit
increateInstances
. Seeing the code increateInstances
though made me realise that my added line in__init__
swallows errors inafterInit
. ButafterInit
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 aDeferred
). However,__new__
does not suffer from this limitation. So the end solution is to put the call toafterInit
intoDBObject.__new__
.As a bonus, I also updated the usage of
DeferredList
increateInstances
to includefireOnFirstErrback=True, consumeErrors=True
so that any exceptions wouldn't go unnoticed.