Skip to content

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

Open
@nishant07

Description

@nishant07

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions