druid-io / pydruid

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

ssl_client_cert passed is being assigned to proxies in Cursor object #300

Open shek1608 opened 1 year ago

shek1608 commented 1 year ago

In function cursor of Class Connection, an object of class Cursor is created with ssl_client_cert and proxies as 7th and 8th parameters respectively as seen here: https://github.com/druid-io/pydruid/blob/master/pydruid/db/api.py#L169-L177

The Cursor object's init has the 2 parameters exchanged, effectively putting ssl_client_cert's value into proxies and vice versa as seen here: https://github.com/druid-io/pydruid/blob/master/pydruid/db/api.py#L199-L208

Example use case from python 3.8 using sqlalchemy:

from sqlalchemy import *
from sqlalchemy.engine import create_engine
engine = create_engine('druid+https://<user>@<host>:<port>/druid/v2/sql', connect_args = {'ssl_client_cert':('<path_to_cert>','<path_to_key>')})
conn = engine.connect();
res = conn.execute('SELECT "<column>" from <table> limit 10');

Having a print statement in the init function will show the value:

print("In cursor's init - ssl_client_cert= {} ; proxies= ".format(ssl_client_cert, proxies))

results in:

In cursor's init - ssl_client_cert= None ; proxies= ('<path_to_cert>','<path_to_key>')

The error thrown for my use case for the conn.execute line was:

  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 711, in merge_environment_settings
    no_proxy = proxies.get('no_proxy') if proxies is not None else None
AttributeError: 'tuple' object has no attribute 'get'

The above led me to debug the code and find this.