Consider using a dynamic class in a pools recreate() method

Issue #2254 resolved
Former user created an issue

Hi,

I stumbled upon this after upgrading to SA 0.7.

I have sub-classed sqlalchemy.pool.QueuePool, without changing its initialization arguments. Still, back in 0.6, I had to override the recreate() method to use self.class instead of QueuePool.

I was fine with that back then. But now, with self.listeners gone, the method slightly changed and I have to differentiate between old and new SA versions in this generic pool.

I found that sqlalchemy.pool.StaticPool already recreates itself by instantiating self.class instead of StaticPool.

Could we implement this in all the other pools, too?

Kind regards, Thomas Wiebe

Comments (5)

  1. Former user Account Deleted

    I'm working behind a firewall that drops sessions pretty early when under load. I use a modified QueuePool to check each connection to be alive before returning it. In case it's gone, I renew the connection and return it then.

  2. Mike Bayer repo owner

    why don't you use the "checkout" event for that ? this is the primary use case this event exists.

  3. Mike Bayer repo owner

    the change is in 9a2edbf3ebf04bfff3ad2a7214605503d5cdcaa2 as it's harmless. However you really should be using the event for this, and if there's some reason the event doesn't work, I'd really like to know as that would be the much more urgent bug here, "pinging" is the main reason the "checkout" event exists and it needs to support what you're doing.

  4. Log in to comment