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

model: only pass "check_same_thread" arg for sqlite database #1662

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Changes from all commits
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
9 changes: 3 additions & 6 deletions reflex/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ def get_engine(url: Optional[str] = None):
)
# Print the SQL queries if the log level is INFO or lower.
echo_db_query = os.environ.get("SQLALCHEMY_ECHO") == "True"
return sqlmodel.create_engine(
url,
echo=echo_db_query,
# Needed for the admin dash.
connect_args={"check_same_thread": False},
)
# Needed for the admin dash on sqlite.
connect_args = {"check_same_thread": False} if url.startswith("sqlite") else {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw the original line was:

connect_args={"check_same_thread": False} if conf.admin_dash else {}

But we don't have the admin_dash in config anymore. Should we still check that arg? I'm not sure what this param does actually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in sqlite, you get an exception if different threads use the same connection; and admin_dash runs on a different thread, so this param ignores that check.

return sqlmodel.create_engine(url, echo=echo_db_query, connect_args=connect_args)


class Model(Base, sqlmodel.SQLModel):
Expand Down