Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nishant07 opened this issue Oct 23, 2018 · 2 comments

Comments

@nishant07
Copy link

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

@sandan
Copy link
Member

sandan commented Nov 6, 2018

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

@blackvitriol
Copy link

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

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

No branches or pull requests

3 participants