Skip to content

flask-shell-bpython interferes with flask-sqlalchemy inside flask shell #13

Open
@bbbart

Description

@bbbart

Please have a look at my Stackoverflow question at https://stackoverflow.com/questions/54268271/sqlalchemy-db-session-commit-behaviour. I'll copy paste it here as reference too:

I'm completely stupefied by the following issue I'm having.

In a flask app with flask_sqlalchemy I'm quite happy creating my model in Python. I have largely the same structure as Miguel Grinberg uses in his Flask Megatutorial.

However, when trying to manually add stuff into the databse (sqlite3) via flask shell, creating some objects, adding them to db.session and then finishing with db.session.commit() doesn't work. No errors, no warnings, no complaints, but also no data in the database, nor in the session itself.

However, when I add a breakpoint() at the bottom of app/init.py, then run flask shell, open a shell again from inside the debugger (I'm using pudb) and then perform the exact same commands as described above, I am getting data in the session and the database.

Smells like a Heisenbug, but it's not so funny a concept when you're confronted with it yourself. :-)

Does anybody have a clue where to start looking for a solution here? I have tried with sqlite://:memory: and with sqlite files at various paths. Digging further into the app, db and db.session objects from pudb didn't teach me anything useful till now.

Thanks for any pointers!

EDIT: I finally found out what was causing the problem: flask-shell-bpython. Simply uninstalling this package, returning the standard REPL to flask shell, solved the issue explained above.

The fact that it did work from the shell launched from pudb, made me try this out (even though pudb is configured to also launch bpython, so it's not the REPL itself that is at fault here).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions