transientskp / tkp

A transients-discovery pipeline for astronomical image-based surveys
http://docs.transientskp.org/
BSD 2-Clause "Simplified" License
19 stars 15 forks source link

Delete dataset monitor error #564

Closed ajstewart closed 3 years ago

ajstewart commented 5 years ago

Similar to #556, the delete dataset function doesn't seem to work when a monitoring list has been used in the run.

(trap-dev) ada:~/ada1/askap/GW/S190814bv/S190814bv-trap$ trap-manage.py deldataset 26

This script will delete dataset 26 with these settings:

        engine:     postgresql
        database:   s190814bv
        user:       aste7152
        password:   aste7152
        host:       localhost
        port:       5432

Are you sure you want to delete dataset 26? [y/N]: y
Traceback (most recent call last):
  File "/suphys/aste7152/.conda/envs/trap-dev/bin/trap-manage.py", line 10, in <module>
    tkp.management.main()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/tkp/management.py", line 375, in main
    args.func(args)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/tkp/management.py", line 276, in deldataset
    db.session.commit()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1027, in commit
    self.transaction.commit()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 494, in commit
    self._prepare_impl()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 473, in _prepare_impl
    self.session.flush()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2459, in flush
    self._flush(objects)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2597, in _flush
    transaction.rollback(_capture_exception=True)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2557, in _flush
    flush_context.execute()
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
    rec.execute(self)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 624, in execute
    uow,
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 348, in delete_obj
    delete,
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1343, in _emit_delete_statements
    c = connection.execute(statement, del_objects)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 988, in execute
    return meth(self, multiparams, params)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1107, in _execute_clauseelement
    distilled_params,
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1253, in _execute_context
    e, statement, parameters, cursor, context
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1473, in _handle_dbapi_exception
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1249, in _execute_context
    cursor, statement, parameters, context
  File "/suphys/aste7152/.conda/envs/trap-dev/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) update or delete on table "dataset" violates foreign key constraint "monitor_dataset_fkey" on table "monitor"
DETAIL:  Key (id)=(26) is still referenced from table "monitor".

[SQL: DELETE FROM dataset WHERE dataset.id = %(id)s]
[parameters: {'id': 26}]
(Background on this error at: http://sqlalche.me/e/gkpj)
AntoniaR commented 3 years ago

This issue is solved here: https://github.com/transientskp/tkp/issues/555#issuecomment-884835694

So closing the issue