Skip to content

Test code "test_postgres.py" failes with sqlalchemy delete method #538

@YasushiMiyata

Description

@YasushiMiyata

Description of the bug

In running the test code "test_postgres.py::test_cand_gen_cascading_delete", program fails by "sqlalchemy.exc.ProgrammingError". Error message is;

E       sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) missing FROM-clause entry for table "candidate"
E       LINE 1: ...E FROM part_temp WHERE part_temp.id = 2 RETURNING candidate....
E                                                                    ^
E       
E       [SQL: DELETE FROM part_temp WHERE part_temp.id = %(id_1)s RETURNING candidate.id]
E       [parameters: {'id_1': 2}]
E       (Background on this error at: http://sqlalche.me/e/14/f405)

To Reproduce

Steps to reproduce the behavior:

  1. Execute pytest test_postgres.py::test_cand_gen_cascading_delete or ci after pull request.

Expected behavior

Test completes with no error.

Error Logs/Screenshots

        # Test that deletion of a Candidate does not delete the Mention
        x = session.query(PartTemp).first()
>       session.query(PartTemp).filter_by(id=x.id).delete(synchronize_session="fetch")

tests/test_postgres.py:119: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/orm/query.py:3124: in delete
    result = self.session.execute(
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/orm/session.py:1670: in execute
    result = conn._execute_20(statement, params or {}, execution_options)
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/base.py:1521: in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/sql/elements.py:313: in _execute_on_connection
    return connection._execute_clauseelement(
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/base.py:1390: in _execute_clauseelement
    ret = self._execute_context(
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/base.py:1749: in _execute_context
    self._handle_dbapi_exception(
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/base.py:1930: in _handle_dbapi_exception
    util.raise_(
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/util/compat.py:211: in raise_
    raise exception
../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/base.py:1706: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f39353b8400>
cursor = <cursor object at 0x7f392ba5a7c0; closed: -1>
statement = 'DELETE FROM part_temp WHERE part_temp.id = %(id_1)s RETURNING candidate.id', parameters = {'id_1': 2}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f392b3380a0>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) missing FROM-clause entry for table "candidate"
E       LINE 1: ...E FROM part_temp WHERE part_temp.id = 2 RETURNING candidate....
E                                                                    ^
E       
E       [SQL: DELETE FROM part_temp WHERE part_temp.id = %(id_1)s RETURNING candidate.id]
E       [parameters: {'id_1': 2}]
E       (Background on this error at: http://sqlalche.me/e/14/f405)

../../test0426/py38fonduer/lib/python3.8/site-packages/sqlalchemy/engine/default.py:716: ProgrammingError

Environment (please complete the following information)

  • OS: Ubuntu 18.04
  • PostgreSQL Version: 10.15
  • Poppler Utils Version: 0.62.0
  • Fonduer Version: 0.8.4+dev
  • Python Version: 3.8.6

Additional context

No error occurs with python 3.6.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions