Am 07.09.2016 um 18:42 schrieb D'Arcy J.M. Cain:
> On Wed, 7 Sep 2016 17:23:24 +0200
> Christoph Zwerschke <[email protected]> wrote:
>> A quick fix would be to set self.db = None at the very beginning of
>> the DB.__init__ method. I'll try to come up with a better fix.
>
> Or, set it as a class variable before __init__ even gets called.  For
> some reason I thought that we already did that.

Another possible fix:

    def __getattr__(self, name):
        if name != 'db' and self.db:
            return getattr(self.db, name)
        raise _int_error('Connection is not valid')

This would raise an InternalErrorwhen self.db is accessed, but not set.

In __del__ we could then check for that error:

    def __del__(self):
        try:
            db = self.db
        except (AttributeError, InternalError):
            db = None
        if db:
            db.set_cast_hook(None)
            if self._closeable:
                db.close()

-- Chris

_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to