druid-io / pydruid

A Python connector for Druid
Other
505 stars 194 forks source link

fix: do_ping to be executed on raw_connection #292

Closed Usiel closed 1 year ago

Usiel commented 1 year ago

Adding a new Druid database on Superset fails, because the pings are unsuccessful. It turns out that pydruid's implementation of do_ping is at fault here and not Superset.

Other dialects expect do_ping to be called on a raw connection (engine.raw_connection() instead of engine.connect() or similar). In fact, we can see that sqlalchemy's pool implementation executes pings on the raw connection, which currently fails for our Druid dialect. When executing pydruid's do_ping on a raw connection we fail because the result of text(...) is not properly parsed to a str.

A simple script shows the problem; I'm setting pool_pre_ping to True here so we get an instant failure, the engine cannot connect because the ping fails.

from sqlalchemy import create_engine

engine = create_engine('druid://localhost:8082/druid/v2/sql', pool_pre_ping=True)
conn = engine.connect()
# => exception
gianm commented 1 year ago

LGTM. thanks @Usiel!