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

Allow for table creation to be optional to allow for table/schema management by other tooling #239

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update docs and add test for new config key SESSION_SQLALCHEMY_CREATE…
…_TABLE
jlgoolsbee committed Apr 24, 2024
commit 261c4919fa4ac8ec72e7b54453573c357c7b5dc3
6 changes: 6 additions & 0 deletions docs/config_reference.rst
Original file line number Diff line number Diff line change
@@ -175,6 +175,12 @@ SqlAlchemy

Default: ``'sessions'``

.. py:data:: SESSION_SQLALCHEMY_CREATE_TABLE

Whether (or not) Flask-Session should manage creation of the table for storing session data.

Default: ``True``

.. py:data:: SESSION_SQLALCHEMY_SEQUENCE

The name of the sequence you want to use for the primary key.
19 changes: 19 additions & 0 deletions tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -57,3 +57,22 @@ def test_use_signer(self, app_utils):
json.loads(byte_string.decode("utf-8")) if byte_string else {}
)
assert stored_session.get("value") == "44"

@pytest.mark.filterwarnings("ignore:No valid SQLAlchemy instance provided")
def test_database_not_created_automatically(self, app_utils):
app = app_utils.create_app(
{
"SESSION_TYPE": "sqlalchemy",
"SQLALCHEMY_DATABASE_URI": "sqlite:///",
"SESSION_SQLALCHEMY_CREATE_TABLE": False,
}
)
with app.app_context() and self.setup_sqlalchemy(
app
) and app.test_request_context():
assert isinstance(
flask.session,
SqlAlchemySession,
)
with pytest.raises(AssertionError):
app_utils.test_session(app)