-
Notifications
You must be signed in to change notification settings - Fork 0
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
added simple project crud #36
Conversation
@KonradUdoHannes Thank you for providing the draft.
async def get_db_session() -> AsyncGenerator[AsyncSession, None]:
async with LocalSession() as session:
try:
yield session
await session.commit()
except Exception as e:
logger.exception(e)
await session.rollback()
raise
finally:
await session.close()
|
@jandix Thanks for the feedback Regarding 1I like the suggested dependency. But is the Regarding 2I think for enums in general we can can probably start by storing String arrays in the database and then implement the enum on the pydantic side. That way we favor flexibility over stability a bit on the DB and still have validation of the data in the API. This should also avoid enum issues related specifically to the DB. Regarding 4I don't see an issue with keeping the revisions separate. Do you have any concerns here? As long as we don't have a continuously running DB with actual we have of course the flexibility to modify revisions without much trouble. Regarding 5I also noticed some slight inconsistencies here. I think its indeed a good point for the next call. |
@jandix I added some tests and set the PR to review. Regarding the database transactions I refactored the current version to use the session makers I also create a script to populate projects from our cms via both their APIs. I didn't commit this script so far because I think we could maybe discuss where to put this and similar scripts, because they are then very CorrelAid specific. At the same time this currently only uses a public endpointof our cms, so everybody could actually run it. I think we should also finish the discussion regarding migrations (merged vs. separate) before merging. |
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.
@KonradUdoHannes I added some proposals regarding style. Regarding the revisions, let's keep it for now. We can discuss this in our next meeting.
backend/src/api/routers/projects.py
Outdated
status: str | None = None | ||
|
||
|
||
async def get_project(project_id: uuid.UUID, session: AsyncSession) -> Project: |
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.
This function could be turned into a dependency:
async def get_project(project_id: uuid.UUID, session: AsyncSession) -> Project: | |
async def get_project(project_id: Annotated[uuid.UUID, Path()], session: Annotated[AsyncSession, SessionWithTransactionContext]) -> Project: |
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.
I actually had issues with that for when using unit of work patterns for ORM update and delete. The issue was that the return value then belonged to the injected session and I needed access to that session in the function that I inject get_project
into. Otherwise I could not continue with the unit of work pattern.
Do you know a solution for this or is the unit of work pattern just not suitable here?
Either way I refactored the dependency injections independently to allow for better testing so the issue is not relevant anymore right now. But I would still be interested in how to solve it (Or whether it does not work with the unit of work pattern)
@jandix Thanks for the review. I actually refactored a little and since the approval stays valid I just wanted to let you know. Basically I encapsulated the database interactions into a separate I also included alembic migrations in the test setup itself. This makes testing a tiny bit more convenient now, and it will allow us to more easily build db tests for CI with sqllite in the future if we want to. |
59dbb12
to
069219e
Compare
Still drafting, but I implemented the basic crud functionality.
@jandix @DatenBergwerker There are mainly two points worth discussing.
status
will be done as part of Implement Project Life cycle functionality scaffolding #23Before finishing the draft I'll still implement a few tests and try to create a first version of a script to populate projects from our cms.