Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

engine execute failed with kerberos auth #43

Open
therealJacobWu opened this issue Dec 15, 2021 · 1 comment
Open

engine execute failed with kerberos auth #43

therealJacobWu opened this issue Dec 15, 2021 · 1 comment

Comments

@therealJacobWu
Copy link

Hi, the following code failed with Error TypeError: can't pickle PyCapsule objects

auth = trino.auth.KerberosAuthentication(service_name=KerberosRemoteServiceName,principal=principal, ca_bundle=ca_bundle)

from sqlalchemy.engine import create_engine
engine = create_engine(
  f'trino://{username}@{presto_host}:{presto_port_ssl}/',
  connect_args={'auth': auth, 'http_scheme':protocol, 'catalog':catalog},
)
table_name='chenhao_test_pandastotrino2'
schema="uip_chenhao_db"
query = dedent('''
    SELECT "table_name"
    FROM "information_schema"."tables"
    WHERE "table_schema" = :schema
      AND "table_name" = :table
''').strip()
sql = sqlalchemy.sql.text(query)
res = engine.execute(sql, schema=schema, table=table_name)

Here is the Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_2376/3114537824.py in <module>
----> 1 res = engine.execute(sql, schema=schema, table=table_name)

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in execute(self, statement, *multiparams, **params)
   2233 
   2234         connection = self._contextual_connect(close_with_result=True)
-> 2235         return connection.execute(statement, *multiparams, **params)
   2236 
   2237     def scalar(self, statement, *multiparams, **params):

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in execute(self, object_, *multiparams, **params)
   1009             )
   1010         else:
-> 1011             return meth(self, multiparams, params)
   1012 
   1013     def _execute_function(self, func, multiparams, params):

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/sql/elements.py in _execute_on_connection(self, connection, multiparams, params)
    296     def _execute_on_connection(self, connection, multiparams, params):
    297         if self.supports_execution:
--> 298             return connection._execute_clauseelement(self, multiparams, params)
    299         else:
    300             raise exc.ObjectNotExecutableError(self)

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _execute_clauseelement(self, elem, multiparams, params)
   1128             distilled_params,
   1129             compiled_sql,
-> 1130             distilled_params,
   1131         )
   1132         if self._has_events or self.engine._has_events:

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1315         except BaseException as e:
   1316             self._handle_dbapi_exception(
-> 1317                 e, statement, parameters, cursor, context
   1318             )
   1319 

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
   1512                 )
   1513             else:
-> 1514                 util.raise_(exc_info[1], with_traceback=exc_info[2])
   1515 
   1516         finally:

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/util/compat.py in raise_(***failed resolving arguments***)
    180 
    181         try:
--> 182             raise exception
    183         finally:
    184             # credit to

/opt/python3common/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1275                 if not evt_handled:
   1276                     self.dialect.do_execute(
-> 1277                         cursor, statement, parameters, context
   1278                     )
   1279 

/opt/python3common/lib/python3.7/site-packages/sqlalchemy_trino/dialect.py in do_execute(self, cursor, statement, parameters, context)
    268     def do_execute(self, cursor: Cursor, statement: str, parameters: Tuple[Any, ...],
    269                    context: DefaultExecutionContext = None):
--> 270         cursor.execute(statement, parameters)
    271         if context and context.should_autocommit:
    272             # SQL statement only submitted to Trino server when cursor.fetch*() is called.

/opt/python3common/lib/python3.7/site-packages/trino/dbapi.py in execute(self, operation, params)
    390                 # At this point the query can be deallocated since it has already
    391                 # been executed
--> 392                 self._deallocate_prepare_statement(added_prepare_header, statement_name)
    393 
    394         else:

/opt/python3common/lib/python3.7/site-packages/trino/dbapi.py in _deallocate_prepare_statement(self, added_prepare_header, statement_name)
    342         # Send deallocate statement. Copy the _request object to avoid poluting the
    343         # one that is going to be used to execute the actual operation.
--> 344         query = trino.client.TrinoQuery(copy.deepcopy(self._request), sql=sql)
    345         result = query.execute(
    346             additional_http_headers={

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181 
    182     # If is its own copy, don't memoize.

/opt/sfdc/python37/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    278     if state is not None:
    279         if deep:
--> 280             state = deepcopy(state, memo)
    281         if hasattr(y, '__setstate__'):
    282             y.__setstate__(state)

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    148     copier = _deepcopy_dispatch.get(cls)
    149     if copier:
--> 150         y = copier(x, memo)
    151     else:
    152         try:

/opt/sfdc/python37/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
    238     memo[id(x)] = y
    239     for key, value in x.items():
--> 240         y[deepcopy(key, memo)] = deepcopy(value, memo)
    241     return y
    242 d[dict] = _deepcopy_dict

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181 
    182     # If is its own copy, don't memoize.

/opt/sfdc/python37/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    278     if state is not None:
    279         if deep:
--> 280             state = deepcopy(state, memo)
    281         if hasattr(y, '__setstate__'):
    282             y.__setstate__(state)

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    148     copier = _deepcopy_dispatch.get(cls)
    149     if copier:
--> 150         y = copier(x, memo)
    151     else:
    152         try:

/opt/sfdc/python37/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
    238     memo[id(x)] = y
    239     for key, value in x.items():
--> 240         y[deepcopy(key, memo)] = deepcopy(value, memo)
    241     return y
    242 d[dict] = _deepcopy_dict

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181 
    182     # If is its own copy, don't memoize.

/opt/sfdc/python37/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    278     if state is not None:
    279         if deep:
--> 280             state = deepcopy(state, memo)
    281         if hasattr(y, '__setstate__'):
    282             y.__setstate__(state)

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    148     copier = _deepcopy_dispatch.get(cls)
    149     if copier:
--> 150         y = copier(x, memo)
    151     else:
    152         try:

/opt/sfdc/python37/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
    238     memo[id(x)] = y
    239     for key, value in x.items():
--> 240         y[deepcopy(key, memo)] = deepcopy(value, memo)
    241     return y
    242 d[dict] = _deepcopy_dict

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    148     copier = _deepcopy_dispatch.get(cls)
    149     if copier:
--> 150         y = copier(x, memo)
    151     else:
    152         try:

/opt/sfdc/python37/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
    238     memo[id(x)] = y
    239     for key, value in x.items():
--> 240         y[deepcopy(key, memo)] = deepcopy(value, memo)
    241     return y
    242 d[dict] = _deepcopy_dict

/opt/sfdc/python37/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    167                     reductor = getattr(x, "__reduce_ex__", None)
    168                     if reductor:
--> 169                         rv = reductor(4)
    170                     else:
    171                         reductor = getattr(x, "__reduce__", None)

TypeError: can't pickle PyCapsule objects

Can anyone please take a look? Thanks!
I tried both sqlchemy-trino both 0.3 and 0.4 versions but got the same error.

@therealJacobWu
Copy link
Author

my guess on this issue is there is some serialization of the object not supported by this module

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant