fix: automated fixes for PR #24#33
Closed
vikram-blaxel wants to merge 2 commits into
Closed
Conversation
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.
Automated fixes for PR #24.
20/20 tests pass. Here is the structured summary:
Security Fixes
models.py+repositories.py+routers.py—isbnfield wired end-to-end (Critical): Addedisbn: strtoBookInandBookOutPydantic schemas; updatedrepositories.create_bookandrepositories.update_bookto passbook.isbnto the ORM constructor/setter. This resolves the NOT NULL integrity error that caused every write to fail.routers.py— Internal exception detail no longer leaked to callers (Critical): Replaceddetail=str(e)in bothcreate_bookandget_booksexception handlers with the generic string"An internal error occurred.". Exceptions are now logged server-side vialogging.create_booknow catchesIntegrityErrorspecifically (400) and falls back to 500 for unexpected errors..env/.gitignore— Plaintext credentials removed from VCS (Critical): Added.envto.gitignoreso it will no longer be committed. Created.env.exampleas a safe template. Added*.dbto.gitignoreto exclude SQLite test artefacts.Dockerfile— Container no longer runs as root (Warning): AddedRUN useradd -m appuserandUSER appuserbeforeCMD.Dockerfile— Uvicorn log level lowered fromtracetoinfo(Warning): Prevents full request/response bodies and auth headers from appearing in production logs.docker-compose.yml— PostgreSQL port bound to loopback only (Warning): Changed"5432:5432"to"127.0.0.1:5432:5432"so the database is not exposed to external networks.requirements.txt— All dependencies pinned to exact versions (Warning): Replaced all>=specifiers with==using the versions confirmed installed in the environment.main.py— OpenAPI docs disabled in production (Informational): Addeddocs_url=None, redoc_url=NonetoFastAPI(...)to avoid advertising the API surface.dependencies.py— Replacedprint()with structuredlogger.error()(Informational): DB init errors now go through the logging framework.Code Quality Fixes
models.py— Removed redundantpassafter docstring inBase(Informational): Eliminated theW0107pylint warning.models.py—String(255)narrowed toString(17)forisbn(Informational): ISBN-13 with hyphens fits in 17 characters; 255 was unnecessarily wide.main.py— Removed redundant router-leveldependencies=[Depends(get_db)](Warning): This was opening and discarding a second DB session per request in addition to each route's ownDepends(get_db).routers.py— Replacedfrom typing import Listwith built-inlist[...](Informational): Modern Python 3.9+ syntax used throughout, consistent with the rest of the codebase.repositories.py+routers.py— Added return-type annotations to all functions (Informational): Improves type-checker effectiveness and IDE support.conftest.py— Removed unused importstextandinspect(not used), keptinspect(it is used bytest_main.py) (Informational): Removedtextimport; keptinspectimport becausetest_main.pyuses it via the fixturetest_engine.test_main.py— Removed unusedcreate_engineimport (Informational).Test Additions
TEST_BOOKSupdated withisbnvalues — Both test-data entries now include a valid ISBN-13 string.isbnassertions added —test_create_book,test_get_book, andtest_update_booknow assert thatbook.isbnequals the expected value after each operation.assert len(books) >= 2uncommented intest_get_books.test_nonexistent_operationssplit into three focused tests:test_get_nonexistent_book,test_update_nonexistent_book,test_delete_nonexistent_book.test_get_books_pagination— New test covering non-defaultskip/limitvalues includinglimit=0.TestBooksRouterclass (9 new HTTP-level tests): Full coverage of all five router endpoints via theclientfixture:test_create_book_http,test_create_book_missing_field_returns_422,test_get_books_http,test_get_book_http,test_get_book_not_found,test_update_book_http,test_update_book_not_found,test_delete_book_http,test_delete_book_not_found.conftest.py—override_get_dbnow uses savepoint/rollback matchingtest_db, so HTTP-level tests also roll back between tests, preventing state leakage. Also added SQLite fallback (DATABASE_URLdefaults tosqlite:///./test.dbwhen not set in the environment) so the test suite runs without a live PostgreSQL instance.Skipped Items
Authentication/authorization on all endpoints (Security Warning): Adding OAuth2/API-key auth would require new dependencies and significant API surface changes that go beyond the scope of a code-quality fix pass. Flagged for a dedicated auth PR.
with_for_update()TOCTOU locking inupdate_book/delete_book(Code Quality Warning): SQLite (used in tests) does not supportSELECT … FOR UPDATE, so adding this would break the test suite without a real PostgreSQL instance. Deferred to a follow-up that adds proper PostgreSQL integration-test infrastructure.Alembic migration for existing rows (Code Quality Critical note): The review flagged that a migration is needed for rows already in the DB. Alembic setup would be a new dependency and a separate migration concern; the column itself was already in the PR and existing-row backfill is a deployment-time concern outside the scope of these fixes.
ISBN format validator in
BookIn(Security/Quality Informational): Adding afield_validatorregex for ISBN-10/13 format is desirable but changes the API contract (rejects previously-accepted values). Left to a follow-up PR to avoid breaking existing integrations.