fix: automated fixes for PR #24#34
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. All changes are staged. Here is the structured summary:
Security Fixes
.gitignore— Added.envand*.dbso the secrets file and local SQLite databases are no longer tracked by git. Also added.env.exampleas a safe template..env— AddedDATABASE_URL=sqlite:///./dev.dbfor local development (the CI workflow overrides this with a real PostgreSQL URL via env injection). The old.envnever had this key, which caused all test runs outside CI to fail.models.py— ISBN format validation via@field_validatorinBookIn: accepts only 10- or 13-digit strings (optionally hyphen-separated), rejecting arbitrary strings before they reach the database.routers.py— Sanitized error messages:create_booknow catchesIntegrityErrorseparately (returns HTTP 409 with a generic message) and wraps the fallbackExceptionwith a generic "Unable to create book." message;get_booksnow returns "Internal server error." rather thanstr(e), preventing schema/stack-trace leakage. Allraise … from echaining added (W0707).Dockerfile— Non-root user: AddedRUN useradd -m appuser+USER appuserbeforeCMDso the container process no longer runs as root. Changed--log-level trace→--log-level infoto stop verbose request/header logging in production.Code Quality Fixes
models.pyisbn: strto bothBookInandBookOut.isbncolumn toString(17)and addedunique=True.passfromBaseclass body (W0107).Bookclass and# Pydantic modelscomment (PEP 8).import reandAnnotated(used by validator).repositories.pycreate_book: now passesisbn=book.isbnwhen constructingmodels.Book.update_book: now setsdb_book.isbn = book.isbnalongside title and author.routers.pyfrom typing import Listto the top (PEP 8 / C0411).from sqlalchemy.exc import IntegrityErrorfor specific exception handling.db.sql— UpdatedCREATE TABLE booksto includeisbn VARCHAR(17) NOT NULL UNIQUEand corrected column lengths/constraints to match the ORM model.conftest.py— Removed unusedinspectandtextimports (F401). Replaced the old savepoint-basedtest_db/test_appfixtures (which leaked state under SQLite) with per-test fresh in-memory SQLite databases usingStaticPool, providing true isolation without requiring a live PostgreSQL instance.Test Additions
test_main.py— Complete overhaul:isbnfield to allTEST_BOOKSconstants and allBookIn(...)call-sites.assert book.isbn == expected_isbnassertions totest_create_book,test_get_book, andtest_update_book.assert len(books) >= 2intest_get_books(now safe due to per-test DB isolation).create_engineimport (F401 ruff).TestHTTPEndpointsclass (12 new tests) covering every router endpoint:test_create_book_http— POST 201, fields including isbn returnedtest_get_books_http— GET 200 returns listtest_get_book_http— GET 200 includes isbntest_get_book_not_found_http— GET 404test_update_book_http— PUT 200 updates all fields including isbntest_update_book_not_found_http— PUT 404test_delete_book_http— DELETE 200, confirms deletion via subsequent GET 404test_delete_book_not_found_http— DELETE 404test_create_book_invalid_isbn_http— POST 422 for invalid ISBN formattest_create_book_missing_fields_http— POST 422 for missing required fieldstest_get_books_pagination_http— GET withlimitandskipboundary valuestest_create_book_duplicate_isbn_http— POST 409 for duplicate ISBNSkipped Items
pip freezeoutput against a known-good environment and a lock-file strategy; doing this blind could introduce incompatibilities. The current packages have no known CVEs per pip-audit.requirements.txtpinning — Same reason as above; no new vulnerabilities introduced.