fix: automated review of PR #24#29
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 8 tests pass. All changes are staged. Here is the structured summary:
Security Fixes
.envcredentials committed to repo — Added.envto.gitignore(with an explanatory comment). Also added*.dbandfile::memory:to prevent SQLite test artefacts from being committed.Dockerfile runs as root — Added
RUN useradd -m appuserandUSER appuserdirectives before theCMDinstruction.--log-level tracein production CMD — Changed to--log-level warningto prevent leaking full HTTP request/response details in logs.PostgreSQL port exposed to all interfaces — Changed
"5432:5432"to"127.0.0.1:5432:5432"indocker-compose.yml, binding only to localhost.detail=str(e)leaking internal error details — Replaced raw exception string forwarding in bothcreate_bookandget_booksrouter handlers with generic sanitized messages ("Failed to create book.","Failed to create book with that ISBN.","Failed to retrieve books."). Full errors are now logged server-side vialogger.error(...).init_dbprinting exception to stdout — Replacedprint(f"Error initializing the database: {e}")independencies.pywithlogger.error("Error initializing the database: %s", e)using Python'sloggingmodule.Code Quality Fixes
isbnfield missing fromBookIn/BookOut/repositories.py— Addedisbn: strto bothBookInandBookOutPydantic schemas. Updatedrepositories.create_bookto passisbn=book.isbn, andrepositories.update_bookto setdb_book.isbn = book.isbn.isbncolumn usesString(255)— Reduced toString(13)(max ISBN-13 length). Addedunique=Trueconstraint to enforce data integrity at the DB level.Redundant
passinBase— Removed thepassstatement from theBase(DeclarativeBase)class body (docstring is sufficient).Missing blank line before
# Pydantic models— Added blank line between the ORMBookclass and the Pydantic section, satisfying PEP 8's two-blank-line rule between top-level definitions.raise HTTPExceptionmissingfrom e— All exception re-raises inrouters.pynow useraise HTTPException(...) from eto preserve the traceback chain.Import order violations — Moved
from typing import Listto the top ofrouters.py(stdlib before third-party). Re-ordered imports independencies.pyto stdlib → third-party → local.Misleading comment
# Create router with prefix— Updated to# Router (prefix "/api" is applied in main.py)to accurately reflect the code.Redundant
dependencies=[Depends(get_db)]oninclude_router— Removed frommain.py; each route handler already declares its ownDepends(get_db), so this opened a redundant unused session per request.Unused imports in
conftest.py— Removed unusedinspectandtextimports. (Note:inspectwas re-added as it's genuinely needed fortest_database_initialization.)Unused
create_engineimport intest_main.py— Removed.test_engineinner variable shadowing the fixture name — Renamed the innertest_engine = create_engine(...)variable toengineinside the fixture body inconftest.py.IntegrityErrormapped to 400 instead of 409 — Thecreate_bookrouter now catchessqlalchemy.exc.IntegrityErrorseparately and returns HTTP 409 Conflict (duplicate ISBN), while other unexpected errors return HTTP 400.Test Additions
isbnfield added toTEST_BOOKS— Both test-book dicts now include a valid"isbn"key with real ISBN-13 values ("9780385533225","9780307887436").Inline
BookIn()calls updated —test_delete_bookandtest_nonexistent_operationsinlineBookIn(...)calls now supply the requiredisbnargument.ISBN assertions added —
test_create_book,test_get_book, andtest_update_booknow assert thatbook.isbnmatches the expected value, providing regression coverage for the new field.Restored
assert len(books) >= 2— The previously commented-out list-length assertion intest_get_bookswas restored.conftest.pytest isolation fixed —test_dbfixture updated to detect SQLite dialect and use a fresh per-testsqlite:///:memory:engine (with schema recreation), since SQLite's savepoint rollback doesn't reliably undo committed data. Non-SQLite databases (PostgreSQL) continue to use the savepoint strategy.Skipped Items
ISBN format validation (Pydantic
@field_validator) — Not implemented. This would be a new feature/validation concern. The column is correctly typed (String(13),unique=True,nullable=False) which provides structural integrity; regex-level format validation would require domain decisions about ISBN-10 vs. ISBN-13 support.Pin exact dependency versions in
requirements.txt— Not changed. Pinning is a dev-ops/dependency-management decision that risks breaking the existing environment and is outside the scope of these fixes (no new dependencies introduced).Pin Dockerfile base image to a digest/patch version — Not changed. Floating
python:3.11is the established project convention; moving to a digest pin is a maintenance workflow decision.conftest.test_approllback alignment — Thetest_app/clientfixture was updated to remove the unusedjoin_transaction_mode, but full savepoint-rollback isolation for HTTP-layer tests was not added since those tests don't currently exist and the review explicitly said "Do NOT modify test intent."Splitting
test_nonexistent_operationsinto separate tests — Intentionally left as-is per the "Do NOT modify test intent" instruction.