-
Notifications
You must be signed in to change notification settings - Fork 0
Update DB config #30
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
Update DB config #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,11 +31,11 @@ class AsyncDB: | |||||||||||||||||||||||||
| get_db = AsyncDB(db_url) | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def __init__(self, db_url: str, meta: MetaData = None, **kwargs) -> None: | ||||||||||||||||||||||||||
| def __init__(self, db_url: str, meta: MetaData = None, engine_config: dict = {}, session_config: dict = {}) -> None: | ||||||||||||||||||||||||||
| self.db_url = db_url | ||||||||||||||||||||||||||
| self.meta = meta | ||||||||||||||||||||||||||
| self.__engine = create_async_engine(db_url) | ||||||||||||||||||||||||||
| self.__async_session = async_sessionmaker(self.__engine, **kwargs) | ||||||||||||||||||||||||||
| self.__engine = create_async_engine(db_url, **engine_config) | ||||||||||||||||||||||||||
| self.__async_session = async_sessionmaker(self.__engine, **session_config) | ||||||||||||||||||||||||||
|
Comment on lines
+34
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using mutable default arguments like
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||
| def engine(self) -> Engine: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines will cause
NameErrorexceptions at runtime.configfunction is no longer defined sincepython-decouplewas removed. Withpydantic-settings, you can just declare the attribute with a default value.DEBUGis not a defined variable in the class scope, so it cannot be used to defineOPENAPI_URL.To fix this and preserve the intended logic, you should use a Pydantic
model_validator. This requires importingmodel_validatorfrompydantic.Here's an example of the full implementation:
The suggested code below provides a minimal fix to make the template parsable, but I strongly recommend implementing the validator pattern for correct behavior.