sdispater / orator

The Orator ORM provides a simple yet beautiful ActiveRecord implementation.
https://orator-orm.com
MIT License
1.43k stars 174 forks source link

TypeError: 'autocommit' is an invalid keyword argument for this function #89

Closed scwood closed 8 years ago

scwood commented 8 years ago

I know there's a similar issue open however mine seems a little bit different. This is happening on my production server but not on local.

ERROR: __main__: Traceback (most recent call last):
  File "main.py", line 53, in <module>
    main()
  File "main.py", line 46, in main
    summary = mhfi_automation.run(testing=args.testing)
  File "/var/www/client-dashboards/etl-v1.1/MHFI/lib/mhfi_automation.py", line 23, in run
    organization.update_directories()
  File "/var/www/client-dashboards/etl-v1.1/MHFI/models/organization.py", line 44, in update_directories
    for assessment in Assessment.all():
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 545, in all
    return instance.new_query().get(columns)
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 1759, in new_query
    builder = self.new_query_without_scopes()
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 1785, in new_query_without_scopes
    self._new_base_query_builder()
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 1813, in _new_base_query_builder
    conn = self.get_connection()
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 2723, in get_connection
    return self.resolve_connection(self.__connection__)
  File "/usr/local/lib/python2.7/site-packages/orator/orm/model.py", line 2757, in resolve_connection
    return cls.__resolver.connection(connection)
  File "/usr/local/lib/python2.7/site-packages/orator/database_manager.py", line 43, in connection
    connection = self._make_connection(name)
  File "/usr/local/lib/python2.7/site-packages/orator/database_manager.py", line 132, in _make_connection
    return self._factory.make(config, name)
  File "/usr/local/lib/python2.7/site-packages/orator/connectors/connection_factory.py", line 36, in make
    return self._create_single_connection(config)
  File "/usr/local/lib/python2.7/site-packages/orator/connectors/connection_factory.py", line 39, in _create_single_connection
    conn = self.create_connector(config).connect(config)
  File "/usr/local/lib/python2.7/site-packages/orator/connectors/mysql_connector.py", line 40, in connect
    return self.get_api().connect(**self.get_config(config))
  File "/usr/lib64/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib64/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: 'autocommit' is an invalid keyword argument for this function

The driver I am using (I think) is PyMySQL, I say I think because in that stack trace it's inside the MySQLdb package. Is there a way I can force Orator to use PyMySQL? Or perhaps I don't understand the stack trace. This is happening when I'm calling .all() on one of my models.

The model code:

class Assessment(Model):
    pass

Here's the SQL dump of the table if that's useful

CREATE TABLE `assessments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `three_sixty_qid` varchar(255) NOT NULL,
  `org_structure_qid` varchar(255) NOT NULL,
  `survey_qid` varchar(255) NOT NULL DEFAULT '',
  `response_set_qid` varchar(255) NOT NULL DEFAULT '',
  `type` varchar(255) NOT NULL,
  `invite_subject` text NOT NULL,
  `invite_body` text NOT NULL,
  `reminder_1_subject` text NOT NULL,
  `reminder_1_body` text NOT NULL,
  `reminder_2_subject` text NOT NULL,
  `reminder_2_body` text NOT NULL,
  `days_to_invite` int(11) DEFAULT NULL,
  `days_to_reminder_1` int(11) NOT NULL,
  `days_to_reminder_2` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
scwood commented 8 years ago

So I have a client deadline that I had to meet and "fixed it" by replacing a block of code in orator/connectors/mysql_connector.py

try:
    import MySQLdb as mysql
    from MySQLdb.cursors import DictCursor as cursor_class
    keys_fix = {
        'password': 'passwd',
        'database': 'db'
    }
except ImportError:
    try:
        import pymysql as mysql
        from pymysql.cursors import DictCursor as cursor_class
        keys_fix = {}
    except ImportError:
        mysql = None

with:

try:
    import pymysql as mysql
    from pymysql.cursors import DictCursor as cursor_class
    keys_fix = {}
except ImportError:
    mysql = None

I'm assuming this problem stems from an old version of MySQLdb on my end or something, unfortunately I can't monkey with the version of that package and a more robust solution like docker isn't available.

sdispater commented 8 years ago

Orator prioritizes MySQLDB over PyMySQL and, for now, there is no way to tell it to use one over the other.

Orator assumes that you are using only one MySQL package in your project.

However, it seems that you have an old version of MySQLDB (propably the mysql-python package that has not been updated in years). Orator only supports the mysqlclient package.

scwood commented 8 years ago

That makes sense. I'll go ahead and close this.