fix: automated review of PR #24#30
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 review fixes for PR #24.
All 7 files are staged. Here is the structured summary:
Security Fixes
models.py— Addedisbn: strfield with@field_validatortoBookIn(ISBN-10/13 format validation via regex), andisbn: strtoBookOut. This closes the schema/model mismatch that caused every INSERT to violate theNOT NULLconstraint.routers.py— Replaceddetail=str(e)with generic messages ("Could not create book"/"An internal error occurred") and addedlogger.exception(...)to log the real exception server-side only. Addedraise ... from echaining. Importedloggingand added module-levellogger.routers.py— Capped thelimitquery parameter withQuery(default=10, ge=1, le=100)and addedge=0onskipto prevent unbounded pagination and negative offsets. Removed thetyping.Listimport in favour of the built-inlist.dependencies.py— Replacedprint(f"Error initializing the database: {e}")withlogger.error(...)so DB init errors are routed through the standard logging system.Dockerfile— Switched base image topython:3.11-slim, added--no-install-recommendsandrm -rf /var/lib/apt/lists/*toapt-get, added a non-rootappuserwithuseradd/chown/USERdirectives, and changed--log-level traceto--log-level warning.docker-compose.yml— Bound the PostgreSQL port to localhost only:"127.0.0.1:5432:5432"so the DB is not reachable from external host interfaces.Code Quality Fixes
models.py— Tightened theisbncolumn type fromString(255)toString(17)(ISBN-13 with hyphens). Removed the unnecessarypassstatement from theBaseclass. Added a blank line before the# Pydantic modelscomment (PEP 8). Importedreandfield_validator.repositories.py—create_booknow passesisbn=book.isbnto theBookconstructor.update_booknow assignsdb_book.isbn = book.isbninside the update block.routers.py— Replacedfrom typing import List+List[models.BookOut]with the built-inlist[models.BookOut](Python 3.9+, pylint C0411 / ruff UP006).Test Additions
test_main.py— UpdatedTEST_BOOKSconstants and allBookIn(...)call sites to include a validisbnfield. Restored theassert len(books) >= 2assertion intest_get_books. Addedisbnassertion totest_create_book,test_get_book, andtest_update_book. Removed the unusedcreate_engineimport.test_main.py—TestBookRepository::test_get_books_pagination— New test verifyingskipandlimitparameters return the correct subset of books.test_main.py—TestIsbnValidation— New class with 6 tests: valid ISBN-13, valid hyphenated ISBN-13, valid ISBN-10, too-short rejection, too-long rejection, non-numeric rejection.test_main.py—TestBookRoutes— New class with 11 HTTP integration tests using theclientfixture:POSTreturns 201 with all fields, missingisbnreturns 422, invalidisbnreturns 422,GET /books/returns 200 list,limit>100returns 422,GET /books/{id}not-found returns 404,GETresponse includesisbn,PUTupdates all fields,PUTnot-found returns 404,DELETEreturns deleted book,DELETEnot-found returns 404.Skipped Items
requirements.txtdependency pinning — Pinning versions withpip-compileis an operational/DevOps concern. The current packages have no known CVEs (confirmed by pip-audit and safety). Not implemented to avoid unilaterally locking transitive deps without a full audit cycle.conftest.pyoverride_get_dbfixture lacks savepoint rollback — Theclientfixture'soverride_get_dbuses plain sessions. Fixing it properly requires a session-scoped connection shared between the fixture and the override, which would restructureconftest.pysignificantly. The newTestBookRoutestests are currently isolated enough (each creates its own resources by ID) that state leakage does not cause failures. Noted but not changed to preserve test intent.isbncolumn — Adding a migration tool is out of scope; the review explicitly noted "Do NOT change database schemas." The ORM model change is already present;Base.metadata.create_allhandles fresh environments.