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

get_session should be available in dialog-lib instead #212

Open
lgabs opened this issue Jun 28, 2024 · 1 comment
Open

get_session should be available in dialog-lib instead #212

lgabs opened this issue Jun 28, 2024 · 1 comment

Comments

@lgabs
Copy link
Contributor

lgabs commented Jun 28, 2024

from dialog.settings import Settings
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, DeclarativeBase
engine = create_engine(Settings().DATABASE_URL)
class Base(DeclarativeBase):
pass
def get_session(): # pragma: no cover
with Session(engine) as session:
yield session

When making plugins using dialog, it's useful to leverage from dialog-lib modules, which are available during development since dialog-lib is distributed package. But since dialog itself is not a package, this function get_session, for example, can not be inspected or accessed (specially when pytests runs and look at available modules). It's only accessed when we run the application using dialog's image.

I think I'd be a good idea to move this functionality to dialog-lib to make it available in the distributed package.

@lgabs
Copy link
Contributor Author

lgabs commented Jun 29, 2024

Even though we could copy/move this to the distributed package, I think the best solution would be to keep session management inside each function that access the database, like I've suggested in #213 , in a way that dialog users shouldn't care about this when using ready functions like generate_memory_instance. Also, each db access would be close to the session creation in code (with context manager), making it easier to maintain and debug the code as the project grows.

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

No branches or pull requests

2 participants