i use session.merge(obj1) insert , upsert rows. , occasionnally errors one:
(pymysql.err.integrityerror) (1062, u"duplicate entry 'q/ftmv4syu5qxencxvx6zghblsfysbo6kgv8sjuzdzww4j1zh3zfhtey/aqvoe5j' key 'primary'") traceback traceback (most recent call last): file "/var/task/streaming_lambda.py", line 71, in lambda_handler session.commit() file "/var/task/sqlalchemy/orm/session.py", line 874, in commit self.transaction.commit() file "/var/task/sqlalchemy/orm/session.py", line 461, in commit self._prepare_impl() file "/var/task/sqlalchemy/orm/session.py", line 441, in _prepare_impl self.session.flush() file "/var/task/sqlalchemy/orm/session.py", line 2137, in flush self._flush(objects) file "/var/task/sqlalchemy/orm/session.py", line 2257, in _flush transaction.rollback(_capture_exception=true) file "/var/task/sqlalchemy/util/langhelpers.py", line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) file "/var/task/sqlalchemy/orm/session.py", line 2221, in _flush flush_context.execute() file "/var/task/sqlalchemy/orm/unitofwork.py", line 389, in execute rec.execute(self) file "/var/task/sqlalchemy/orm/unitofwork.py", line 548, in execute uow file "/var/task/sqlalchemy/orm/persistence.py", line 181, in save_obj mapper, table, insert) file "/var/task/sqlalchemy/orm/persistence.py", line 799, in _emit_insert_statements execute(statement, multiparams) file "/var/task/sqlalchemy/engine/base.py", line 945, in execute return meth(self, multiparams, params) file "/var/task/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) file "/var/task/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement compiled_sql, distilled_params file "/var/task/sqlalchemy/engine/base.py", line 1189, in _execute_context context) file "/var/task/sqlalchemy/engine/base.py", line 1393, in _handle_dbapi_exception exc_info file "/var/task/sqlalchemy/util/compat.py", line 202, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) file "/var/task/sqlalchemy/engine/base.py", line 1182, in _execute_context context) file "/var/task/sqlalchemy/engine/default.py", line 469, in do_execute cursor.execute(statement, parameters) file "/var/task/pymysql/cursors.py", line 166, in execute result = self._query(query) file "/var/task/pymysql/cursors.py", line 322, in _query conn.query(q) file "/var/task/pymysql/connections.py", line 835, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) file "/var/task/pymysql/connections.py", line 1019, in _read_query_result result.read() file "/var/task/pymysql/connections.py", line 1302, in read first_packet = self.connection._read_packet() file "/var/task/pymysql/connections.py", line 981, in _read_packet packet.check_error() file "/var/task/pymysql/connections.py", line 393, in check_error err.raise_mysql_exception(self._data) file "/var/task/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) integrityerror: (pymysql.err.integrityerror) (1062, u"duplicate entry 'q/ftmv4syu5qxencxvx6zghblsfysbo6kgv8sjuzdzww4j1zh3zfhtey/aqvoe5j' key 'primary'") [sql: u'insert user_table (_id, collection_name, platform, created_at, updated_at, deleted, account_complete, population_current, state, stars, language, age_range, private_account, user_credit, new_user, anonymous) values (%(_id)s, %(collection_name)s, %(platform)s, %(created_at)s, %(updated_at)s, %(deleted)s, %(account_complete)s, %(population_current)s, %(state)s, %(stars)s, %(language)s, %(age_range)s, %(private_account)s, %(user_credit)s, %(new_user)s, %(anonymous)s)'] [parameters: {'user_credit': 0, 'age_range': none, 'anonymous': 0, 'language': none, 'new_user': 1, 'collection_name': none, 'created_at': datetime.datetime(2000, 1, 1, 0, 0), 'deleted': 0, 'account_complete': none, 'updated_at': none, 'platform': 'undefined', 'state': none, 'stars': none, '_id': 'q/ftmv4syu5qxencxvx6zghblsfysbo6kgv8sjuzdzww4j1zh3zfhtey/aqvoe5jms3lkmkns0lkrc+uzeifdhg32wqwg6efm+h4ofptf1kzskip54yj243av+lqfsrqojd5seocn178sodeamfeeprhzy3s9nw6ro1e64zpxoy=', 'private_account': 0, 'population_current': 'undefined'}]
i'm using sqlalchemy 0.9.1 , pymysql 0.7.9 communicate in mysql rds mysql database. how can session.merge()
generate duplicate entry error? isn't purpose?
Comments
Post a Comment