Add contact photo field to API - #3
Conversation
patrickboxfordpartners
commented
Aug 27, 2026
- Add photo field to Contact model as Text (stores base64 image data)
- Add photo field to all contact schemas (ContactBase, ContactUpdate)
- Update example data to include photo field
- Allows users to upload and store profile pictures with contacts
- Add photo field to Contact model as Text (stores base64 image data) - Add photo field to all contact schemas (ContactBase, ContactUpdate) - Update example data to include photo field - Allows users to upload and store profile pictures with contacts
PR Summary by QodoAdd contact photos to persistence and API schemas
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Existing databases cannot upgrade
|
| country: Mapped[str | None] = mapped_column(String(120)) | ||
|
|
||
| notes: Mapped[str | None] = mapped_column(Text) | ||
| photo: Mapped[str | None] = mapped_column(Text) |
There was a problem hiding this comment.
1. Existing databases cannot upgrade 🐞 Bug ≡ Correctness
Adding Contact.photo only changes SQLAlchemy metadata; startup uses create_all(), which does not add columns to an existing contacts table. Deployments using the documented persistent SQLite or PostgreSQL configuration will fail ORM reads and writes because generated contact queries reference a nonexistent photo column.
Agent Prompt
## Issue description
Existing persistent databases are not upgraded when the new `Contact.photo` ORM column is deployed, so contact queries fail against the old table schema.
## Issue Context
`Base.metadata.create_all()` creates missing tables but does not alter existing ones. Introduce and execute a versioned migration that adds a nullable text `photo` column while preserving existing contact rows.
## Fix Focus Areas
- app/models.py[32-34]
- app/database.py[48-52]
- app/main.py[60-68]
- tests/conftest.py[15-20]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| photo: str | None = Field( | ||
| default=None, | ||
| description="Contact photo as base64-encoded image data (data URI format).", | ||
| examples=["data:image/jpeg;base64,/9j/4AAQSkZJRg..."], |
There was a problem hiding this comment.
2. Photo payload is unconstrained 🐞 Bug ☼ Reliability
The photo fields accept arbitrary, unlimited strings rather than validating the promised image data URI or limiting decoded size. Those values are stored verbatim and included in every ContactRead, so malformed images are accepted and oversized uploads can inflate database, memory, and list responses of up to 200 contacts without bound.
Agent Prompt
## Issue description
Photo input currently accepts arbitrary and unlimited text, allowing invalid image values and resource-exhausting payloads to be persisted and returned by the API.
## Issue Context
Apply the same reusable validator to create/replace and patch schemas. Require an allowed image data-URI MIME type, strict base64 decoding, and a conservative decoded-byte limit; reject invalid or oversized values with validation errors, and add coverage for all mutation paths. Also avoid embedding full image data in collection representations if normal allowed image sizes can make a 200-item page excessive.
## Fix Focus Areas
- app/schemas.py[72-76]
- app/schemas.py[114-143]
- app/schemas.py[146-150]
- app/routers/contacts.py[66-108]
- tests/test_contacts_api.py[1-1]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools