Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with stored procedure with commit #1001

Open
lucabergamini opened this issue Aug 14, 2024 · 0 comments
Open

Error with stored procedure with commit #1001

lucabergamini opened this issue Aug 14, 2024 · 0 comments

Comments

@lucabergamini
Copy link

What action do you want to perform

I'm running a test which does something similar to to following code:

stored_proc_create = """
    CREATE OR REPLACE PROCEDURE test_stored_procedure_commit() LANGUAGE plpgsql AS $$
    BEGIN
        COMMIT;
    END;
    $$;
    """

    async with db.session() as session:
        await session.execute(sa.text(stored_proc_create))

    async with db.session(SessionType.AUTO_COMMIT) as session:
        await session.execute(sa.text("CALL test_stored_procedure_commit();"))

where db is a fixture from the library:

postgresql_proc_load_db = factories.postgresql_proc(load=[load_database])
postgresql_load_db = factories.postgresql("postgresql_proc_load_db")

(load_database does some initialisation for some data, this is part of a bigger project)

My setup is sqlalchemy over asyncpg and I'm ensuring I'm setting the session to auto-commit level in sqlalchemy.

What are the results

I'm getting

sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.InvalidTransactionTerminationError'>: invalid transaction termination

which points to nested transactions or a session without autocommit preventing the stored procedure to commit

What are the expected results

The same exact code works while running regular code outside a test. Is this expected to work with pytest-postgres?

I can try to get to a more minimal example if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant