fix: automated review of PR #24#28
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.
18/18 tests pass. Here is the structured summary:
Security Fixes
.envcommitted with plaintext credentials — Added.envto.gitignore(andtest.dbwhile there). Created.env.examplewith placeholder values as a safe template for contributors.Container runs as root (CWE-250) — Added
RUN useradd -m appuserandUSER appusertoDockerfilebeforeCMD.Verbose trace log level in production image — Changed
--log-level trace→--log-level infoinDockerfile CMD.Internal exception details leaked to API clients —
routers.py:create_booknow returns generic"Invalid request data"/"Internal server error"messages;get_booksreturns"Internal server error". Rawstr(e)is never sent to callers. All exceptions are logged server-side vialogging.PostgreSQL port exposed on all interfaces — Changed
docker-compose.ymldbportsbinding from"5432:5432"→"127.0.0.1:5432:5432".raise ... from emissing (exception chain dropped) — Allraise HTTPException(...)calls inrouters.pynow useraise ... from eto preserve the exception chain for debugging.Code Quality Fixes
isbnfield missing fromBookIn/BookOutand repositories — Addedisbn: strto both Pydantic models (BookIn,BookOut).repositories.create_booknow passesisbn=book.isbn;repositories.update_booknow setsdb_book.isbn = book.isbn.Redundant
nullable=FalseonMapped[str]— Removed frommodels.py;Mapped[str]already implies NOT NULL in SQLAlchemy 2.x.Unnecessary
passinBaseclass — Removed thepassstatement (class already has a docstring).Duplicate
Depends(get_db)on router — Removeddependencies=[Depends(get_db)]fromapp.include_router(...)inmain.py; each route already declares its owndbdependency. Removed now-unusedDependsimport.Broad
except Exception→ specific exceptions increate_book— CatchesIntegrityError(→ 409 Conflict),SQLAlchemyError(→ 500), then falls back to generic 400 for other errors.Limit cap for
GET /books/—get_booksnow capslimit = min(limit, 100)to prevent resource exhaustion.Wrong import order in
routers.py— Movedfrom typing import Listandimport loggingto the top; stdlib before third-party imports.Unused imports removed —
conftest.py: removedinspectandtextfrom sqlalchemy imports (re-addedinspecttotest_main.pywhere it's actually used).test_main.py: removed unusedcreate_engineimport.Variable shadowing fixed in
conftest.py— Renamed innertest_enginevariable →enginein thetest_enginefixture; renamedTestingSessionLocal→session_factoryintest_app.Blank line before
# Pydantic modelscomment — Added tomodels.pyfor PEP 8 compliance.Tests use hermetic SQLite —
conftest.pynow setsDATABASE_URLto a SQLite file URI before importing application modules, making the test suite runnable without an external PostgreSQL server.Test Additions
Added a new
TestBookRoutesclass intest_main.pywith 10 HTTP-layer integration tests using the existingclientfixture:test_create_book_returns_201— POST creates a book, returns 201 + body with all fields includingisbntest_create_book_invalid_body_returns_422— missing required fields returns 422test_get_books_returns_200— GET list returns 200 + JSON arraytest_get_book_returns_200— GET single book by ID returns 200test_get_book_not_found_returns_404— GET unknown ID returns 404test_update_book_returns_200— PUT updates all fields, returns 200test_update_book_not_found_returns_404— PUT unknown ID returns 404test_delete_book_returns_200— DELETE removes book, second GET returns 404test_delete_book_not_found_returns_404— DELETE unknown ID returns 404test_get_books_limit_cap—limit=9999is accepted (capped internally) and returns 200Also updated all existing repository tests and
TEST_BOOKSconstants to includeisbn(fixing the 5 previously failing tests). Uncommentedassert len(books) >= 2intest_get_books. Addedisbnassertions totest_create_bookandtest_update_book.Skipped Items
requirements.txt) — Not implemented. Pinning requires knowing the currently installed exact versions and could break the existing CI if the pinned versions differ from what the workflow installs. This is a supply-chain hygiene improvement best done as a separate dedicated change with proper lockfile tooling (pip-compile)./docsand/redocin production (main.py) — Not implemented. This is an operational/deployment concern; disabling them would break developer experience in non-production environments and the review flagged it as informational only.String(13)for ISBN /unique=True— Not implemented. The review notes say "Do NOT change database schemas." Changing the column length or adding a uniqueness constraint would alter the schema.python:3.11→ pinned digest/slim variant in Dockerfile — Not implemented; no new dependencies/base changes were requested and this is informational..envfrom git history — Cannot be done with a simplegit add; requiresgit filter-repo/ BFG which would rewrite history. The file is now in.gitignoreand future commits will not track it. Credential rotation is an operational action outside the scope of code fixes.