ruby-pg icon indicating copy to clipboard operation
ruby-pg copied to clipboard

inheritence issue with pg version >= 1.3.0

Open KiriakosGeorgiou opened this issue 3 years ago • 3 comments
trafficstars

Up until pg version 1.2.3 I could inherit from PG::Connection like this:

class PGx::Connection < PG::Connection
  def initialize(*args)
  ....
  end
end

and my derived class' initialize() would be called first, as expected. Starting with pg 1.3.0 onward, the derived class' initialize() is not called at all. I tried for a couple of days to get to the bottom of this, without success. Can you steer me in the right direction?

I use ruby 2.7.6

thanks!

KiriakosGeorgiou avatar Sep 07 '22 15:09 KiriakosGeorgiou

You're right, PG::Connection#initialize is no longer called since pg-1.3.

I made a change to PG::Connection which reactivates the call here but I'm not convinced, that this change should be merged. initialize might be called multiple times per call to PG::Connection.new and gets different arguments. initialize is more kind of internal method, not intended to be derived.

Can you please describe more about your use case for deriving PG::Connection?

larskanis avatar Sep 10 '22 21:09 larskanis

My use case: I extended pg to provide logging, retrying and reconnecting. Documentation is here: http://www.mockbites.com/articles/tech/pgx

KiriakosGeorgiou avatar Sep 12 '22 14:09 KiriakosGeorgiou

I think it's best to derive PG::Connection.new instead of PG::Connection#initialize. Also note that there are several alias methods: https://github.com/ged/ruby-pg/blob/master/lib/pg/connection.rb#L684-L687

larskanis avatar Sep 15 '22 19:09 larskanis