airflow icon indicating copy to clipboard operation
airflow copied to clipboard

sqlalchemy.exc.IntegrityError

Open nocrosstalk opened this issue 11 years ago • 10 comments

I've setup the default dags that come with the installation. Celery/RabbitMQ is working now and when I run a task, I get this error:

sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: task_instance.task_id, task_instance.dag_id, task_instance.execution_date [SQL: u'INSERT INTO task_instance (task_id, dag_id, execution_date, start_date, end_date, duration, state, try_number, hostname, unixname, job_id, pool, queue, priority_weight) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('print_the_context', 'example_python_operator', '2015-01-01 00:00:00.000000', '2015-07-28 05:27:40.692490', None, None, 'running', 1, 'SRV01', 'root', '8', None, 'celery', 11)]

nocrosstalk avatar Jul 28 '15 11:07 nocrosstalk

I installed postgres and set it up, same error:

sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) duplicate key value violates unique constraint "task_instance_pkey"
DETAIL:  Key (task_id, dag_id, execution_date)=(print_date, tutorial, 2015-07-28 00:00:00) already exists.
 [SQL: 'INSERT INTO task_instance (task_id, dag_id, execution_date, start_date, end_date, duration, state, try_number, hostname, unixname, job_id, pool, queue, priority_weight) VALUES (%(task_id)s, %(dag_id)s, %(execution_date)s, %(start_date)s, %(end_date)s, %(duration)s, %(state)s, %(try_number)s, %(hostname)s, %(unixname)s, %(job_id)s, %(pool)s, %(queue)s, %(priority_weight)s)'] [parameters: {'hostname': 'BNA001082-SRV01', 'end_date': None, 'task_id': 'print_date', 'execution_date': datetime.datetime(2015, 7, 28, 0, 0), 'job_id': '1', 'try_number': 1, 'queue': 'celery', 'state': 'running', 'dag_id': 'tutorial', 'duration': None, 'priority_weight': 3, 'start_date': datetime.datetime(2015, 7, 28, 7, 31, 34, 429420), 'pool': None, 'unixname': 'root'}]

nocrosstalk avatar Jul 28 '15 13:07 nocrosstalk

Can you describe what you're doing/how you setup airflow in a little more detail?

jomar83 avatar Jul 28 '15 13:07 jomar83

Setup airflow according to the tutorial on an Ubuntu server. Setup Celery accordingly, RabbitMQ, installed postgresql, created username, password, etc. ran airflow initdb (no errors). Then I run airflow worker -q celery (that's the queue I defined) and run airflow weberver -p 8080. I see the default example dags, but when I try to run a task I get this error

nocrosstalk avatar Jul 28 '15 13:07 nocrosstalk

Which driver are you using for postgres (at the beginning of your sql alchemy URI)?

relevant: https://github.com/airbnb/airflow/issues/161

mistercrunch avatar Jul 28 '15 22:07 mistercrunch

I use this: postgresql://username:password@localhost/database

Connection seems to be OK, database is filled.

nocrosstalk avatar Jul 29 '15 06:07 nocrosstalk

Sorry about the delay, can you provide the full stack trace and airflow version you are using?

mistercrunch avatar Aug 12 '15 05:08 mistercrunch

Please reopen if it's sitll a problem

mistercrunch avatar Aug 28 '15 17:08 mistercrunch

Similar issue: I'm currently testing using celery, rabbitmq and mysql for celery backend. Examples run fine, but a simple test with one BashOperator (it calls a php script) and the worker throws this:

Traceback (most recent call last): File "/usr/local/bin/airflow", line 10, in args.func(args) File "/usr/local/lib/python2.7/site-packages/airflow/bin/cli.py", line 128, in run job_id=args.job_id, File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 956, in run session.commit() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 801, in commit self.transaction.commit() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 392, in commit self._prepare_impl() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 372, in _prepare_impl self.session.flush() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2015, in flush self._flush(objects) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2133, in _flush transaction.rollback(_capture_exception=True) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 60, in exit compat.reraise(exc_type, exc_value, exc_tb) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2097, in _flush flush_context.execute() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 373, in execute rec.execute(self) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 532, in execute uow File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 174, in save_obj mapper, table, insert) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 752, in _emit_insert_statements execute(statement, multiparams) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute return meth(self, multiparams, params) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement compiled_sql, distilled_params File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context context) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception exc_info File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause reraise(type(exception), exception, tb=exc_tb) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context context) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute self.errorhandler(self, exc, value) File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError) (1062, "Duplicate entry 'task-dag-2015-10-22 17:27:29' for key 'PRIMARY'") [SQL: u'INSERT INTO task_instance (task_id, dag_id, execution_date, start_date, end_date, duration, state, try_number, hostname, unixname, job_id, pool, queue, priority_weight, operator, queued_dttm) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'] [parameters: ('macromeasures_user_twitter_1', 'macromeasures', datetime.datetime(2015, 10, 22, 17, 27, 29, 30119), datetime.datetime(2015, 10, 22, 17, 29, 1, 892482), datetime.datetime(2015, 10, 22, 17, 29, 3, 247135), 1, 'success', ... ...

The task instance is always stuck at the running stage. This was done on a fresh airflow db.

Any pointer would be awesome!

cadupont avatar Oct 22 '15 21:10 cadupont

Actually, even with the sequential executor, I get the same error from the scheduler. I renamed the operator's instance (the task), doesn't change anything, same error. The php script runs fine in standalone.

cadupont avatar Oct 23 '15 13:10 cadupont

If I mark the first task instance as successful, it seems every subsequent ones will run fine.

Also, (might be a separate issue) the tree view shows empty boxes while I have 9 successful runs, and the range being displayed definitely fit the runs.

cadupont avatar Oct 23 '15 15:10 cadupont