fix(python): commit transaction after creating lamp#407
Merged
Conversation
The create method was only calling flush() which sends SQL within the open transaction but never committed it. When the session closed at the end of the POST request, SQLAlchemy rolled back the uncommitted transaction, so the lamp was never persisted. Subsequent GET requests correctly returned 404. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes persistence of newly created lamps when using the PostgreSQL repository by ensuring the INSERT is committed so subsequent requests/sessions can read the row.
Changes:
- Add an explicit
commit()toPostgresLampRepository.create()afterflush()
Comment on lines
58
to
61
| self._session.add(db_lamp) | ||
| await self._session.flush() | ||
| await self._session.commit() | ||
| await self._session.refresh(db_lamp) |
There was a problem hiding this comment.
Test coverage gap: the existing PostgresLampRepository integration tests exercise create() and then get() within the same SQLAlchemy session/transaction, which would still pass even if create() only did flush() (the root cause described in the PR). To prevent regressions, add a test that creates a lamp, closes the session/request, and then uses a new session/repository instance to get() the lamp and assert it is found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostgresLampRepository.create()was callingflush()but nevercommit(), so the INSERT was sent within the open transaction but rolled back when the session closed at the end of the requestupdateanddeleteboth hadcommit()—createwas simply missing itTest plan
🤖 Generated with Claude Code