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

shared: removed 'text()' from cursor.execute #169

Closed
wants to merge 1 commit into from

Conversation

psaiz
Copy link
Contributor

@psaiz psaiz commented Aug 23, 2023

Description

Rolls back part of psaiz@5fc0fc9.
It looks like the connection.execute and cursor.execute expect different arguments. The former is a text, the latter a string.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Third-party code

If you've added third-party code (copy/pasted or new dependencies), please reach out to an architect.

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@psaiz
Copy link
Contributor Author

psaiz commented Aug 23, 2023

This is the error that I got in invenio-stats before having this patch


dbapi_connection = <sqlite3.Connection object at 0x1178845e0>, connection_record = <sqlalchemy.pool.base._ConnectionRecord object at 0x11789bc90>

    def do_sqlite_connect(dbapi_connection, connection_record):
        """Ensure SQLite checks foreign key constraints.
    
        For further details see "Foreign key support" sections on
        https://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#foreign-key-support
        """
        # Enable foreign key constraint checking
        cursor = dbapi_connection.cursor()
>       cursor.execute(text("PRAGMA foreign_keys=ON"))
E       TypeError: execute() argument 1 must be str, not TextClause

/usr/local/lib/python3.11/site-packages/invenio_db/shared.py:95: TypeError

I'm a bit confused why the error didn't appear on this module...

@utnapischtim
Copy link
Contributor

@psaiz please check first your Sqlalchemy version. the TextClause will be used in the future, but old versions does not support it. Maybe you have the wrong SQLAlchemy version installed locally.

@psaiz
Copy link
Contributor Author

psaiz commented Sep 1, 2023

Hi @utnapischtim,

Thanks for looking into this. I see this error in the pipelines of other modules that depend on invenio-db. It might be that invenio-db requires an old version of SQLAlchemy, and then this is still something that should be addressed in the invenio-db module

@utnapischtim
Copy link
Contributor

@psaiz
I think there is another problem in the invenio-previewer package. Invenio-db works with the same installed SQLAlchemy version as invenio-previewer, for FlaskSQLAlchemy it is the same version too.

Further i don't think that invenio-db should handle that. Invenio-db is working as expected with the installed packages. Otherwise the error should also pop up in on the invenio-db tests. My problem with removing the compatibility with newer SQLAlchemy versions in invenio-db is that it would be a problem in the future so i think it is the better way to improve invenio-previewer first.

What i see too is that invenio-previewer is using sqlite, maybe that introduces a problem which is not tested in invenio-db.

Since the error is happening on doctest you could update those packages (e.g. Sphinx) first on invenio-previewer and see if that fixes the problem?

@ntarocco
Copy link
Contributor

@utnapischtim it turned out that we were never testing sqlite here in invenio-db. In the PR below, we have added the sqlite tests in the CI matrix.
The change proposed by @psaiz is the one in the official documentation: https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#foreign-key-support

Closing because superseded by: #171

@ntarocco ntarocco closed this Sep 11, 2023
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

Successfully merging this pull request may close these issues.

3 participants