sqlalchemy-teradata icon indicating copy to clipboard operation
sqlalchemy-teradata copied to clipboard

python 2.7 gives TypeError: super() argument 1 must be type, not classobj

Open nishant07 opened this issue 6 years ago • 2 comments

Hi Team,

I was trying to create SQLAlchemy engine as per below sample code.

from sqlalchemy import create_engine
td_engine = create_engine('teradata://dbuser:[email protected]')

Executing this statement gave me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 425, in create_engine
    return strategy.create(*args, **kwargs)
  File "/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 92, in create
    (cargs, cparams) = dialect.create_connect_args(u)
  File "/anaconda2/lib/python2.7/site-packages/sqlalchemy_teradata/dialect.py", line 129, in create_connect_args
    cparams['dataTypeConverter'] = TDDataTypeConverter()
  File "/anaconda2/lib/python2.7/site-packages/sqlalchemy_teradata/data_type_converter.py", line 13, in __init__
    super(TDDataTypeConverter, self).__init__(*args, **kwargs)
TypeError: super() argument 1 must be type, not classobj

I am using Python 2.7.15 I looked at the stackoverflow, and found this answer: TypeError: super() argument 1 must be type, not classobj
As per the answers, super() and all subclass/superclass stuff only works with new-style classes. Old-style classes (also known as "classic" classes) are always of type classobj; new-style classes are of type type To get rid of this error, we can use multiple inheritance as per the 2nd answer

So I changed the class definition of the class TDDataTypeConverter in data_type_converter.py as below, and it resolved the issue:

class TDDataTypeConverter(DefaultDataTypeConverter, object):

    def __init__(self, *args, **kwargs):
        super(TDDataTypeConverter, self).__init__(*args, **kwargs)

    def _process_data_type(self, dataType):
        if 'INTERVAL' in dataType:
            return dataType.replace('_', ' ')
        return dataType

    def convertValue(self, dbType, dataType, typeCode, value):
        dataType = self._process_data_type(dataType)
        return super(TDDataTypeConverter, self).convertValue(
            dbType, dataType, typeCode, value)

So can you please integrate these changes to the code base, so no one faces any such issues with python 2.7?

Let me know if you need any further details.

Thank you, Nishant

nishant07 avatar Oct 23 '18 21:10 nishant07

@nishant07 Thanks, since python 2.7 is nearing its end we are moving to using python3. Could you open a PR with the change?

sandan avatar Nov 06 '18 19:11 sandan

I am having this problem trying to connect to a database. Any updates on this ?

blackvitriol avatar Mar 27 '19 14:03 blackvitriol