fix: automated fixes for PR #24#36
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.
All 18 tests pass and all changes are staged. Here is the structured summary:
Security Fixes
models.py— Removed redundantnullable=Falsefromisbn(non-optionalMapped[str]already implies NOT NULL); addedunique=Trueto enforce ISBN uniqueness at the database level; changedString(255)toString(17)(max valid ISBN-with-hyphens length).routers.py— Replaced bareexcept Exception as e: raise HTTPException(detail=str(e))increate_bookwithexcept IntegrityErrorthat returns a generic error message (no raw DB internals leaked). Addedfrom None/from eexception chaining to all handlers. Removed thefrom typing import Listimport (used built-inlist[...]).Dockerfile— AddedRUN pip install --upgrade pip wheelto pick up security fixes in those build tools. AddedRUN useradd -m appuser+USER appuserso the container process no longer runs as root. Changed--log-level trace→--log-level infoto prevent sensitive payloads/traces from being written to stdout in production.docker-compose.yml— Removed theports: "5432:5432"mapping from thedbservice so the PostgreSQL port is no longer exposed to the host; the web service reaches it via the internal Docker network.Code Quality Fixes
models.py— Addedisbn: strto bothBookInandBookOutPydantic schemas so the field is part of the API contract.repositories.py— Updatedcreate_bookto passisbn=book.isbnwhen constructingBook; updatedupdate_bookto assigndb_book.isbn = book.isbn; added docstrings to all functions.db.sql— Addedisbn VARCHAR(17) UNIQUE NOT NULLto theCREATE TABLEstatement so fresh deployments match the ORM model.conftest.py— Removed unusedtextimport (was flagged as F401). RenamedTestingSessionLocaltotesting_session_local(PEP 8 snake_case for variables). Fixed thetest_appfixture to use a single shared connection/transaction with savepoint rollback, giving the HTTP client proper cross-request visibility while still cleaning up after each test.test_main.py— Removed unusedcreate_engineimport (F401). Restoredassert len(books) >= 2intest_get_books(now safe with proper rollback isolation).Test Additions
test_main.py— newTestBookRouterclass (10 tests):test_create_book_http— POST/api/books/returns 201 with all fields includingisbn.test_create_book_invalid_payload— Missing required fields returns 422.test_get_books_http— GET/api/books/returns a list.test_get_books_pagination—skipandlimitquery parameters are respected.test_get_book_http— GET/api/books/{id}returns the correct book.test_get_book_not_found— Returns 404 for unknown ID.test_update_book_http— PUT/api/books/{id}updates title, author, and isbn.test_update_book_not_found— Returns 404 for unknown ID.test_delete_book_http— DELETE/api/books/{id}removes the book (confirmed with follow-up GET → 404).test_delete_book_not_found— Returns 404 for unknown ID.isbninTEST_BOOKS, inlineBookIn(...)calls, andassertchecks on theisbnfield.Skipped Items
@field_validatorfor ISBN format — Noted as informational. A strict ISBN-10/13 validator is a useful hardening step but was not added here to avoid breaking tests that use numeric-only mock ISBNs that aren't strictly valid (e.g.9780000000001). Recommended as a follow-up.db.sqlDDL file and SQLAlchemyBase.metadata.create_allalready handle fresh deployments correctly; a migration script for existing live databases is recommended as a separate operational task.conftest.pyseparate test database URL — The tests run against whateverDATABASE_URLis set in the environment (matching CI behaviour). A fully isolated test-only database URL config was not added to avoid breaking the CI workflow.