[US-1.1 / OBT-198] Edit language name and code (PUT) - #96
Conversation
Add PUT /api/languages/{id} to update a language's name and/or code after
creation. Enforce code uniqueness (409 on conflict), return 404 for an
unknown id, and expose an auto-updating updated_at timestamp.
- Language model: add updated_at column
- Schemas: LanguageUpdate + updated_at on LanguageResponse
- update_language service normalizes code and validates uniqueness
- Alembic migration adds updated_at, backfilled from created_at
Per the 2026-07 rule change, editing a language directly (PUT) is now platform-admin only; managers submit an edit request instead (delivered by the change-requests feature). The PUT route depends on require_platform_admin.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: QUIET Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds partial language updates through a platform-admin-protected endpoint, with code normalization and uniqueness checks. Adds ChangesLanguage Update
Sequence Diagram(s)sequenceDiagram
participant Client
participant LanguagesAPI
participant LanguageService
participant Database
Client->>LanguagesAPI: PUT language update
LanguagesAPI->>LanguageService: Update language
LanguageService->>Database: Load, validate, and commit changes
Database-->>LanguageService: Return refreshed language
LanguageService-->>LanguagesAPI: Return updated language
LanguagesAPI-->>Client: Return LanguageResponse
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/services/language/update_language.py`:
- Around line 19-31: Update the update-language flow around db.commit() to catch
IntegrityError from concurrent unique-code conflicts, roll back the session, and
raise ConflictError so the request returns 409 instead of 500. Preserve the
existing pre-commit lookup and successful commit/refresh behavior in the
surrounding update logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: e132abc7-d85c-4ed9-a145-d9dd25f625cc
📒 Files selected for processing (7)
alembic/versions/20260704_0002_add_language_updated_at.pyapp/api/languages.pyapp/db/models/language.pyapp/models/language.pyapp/services/language/__init__.pyapp/services/language/update_language.pytests/test_language_service.py
… conflict Also drop the update_language docstring to match service conventions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@coderabbitai — decision on this review:
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd update_language.py --exec cat -n {}Length of output: 1562 Confirmed — the updated code correctly wraps the |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/services/language/update_language.py (1)
10-16: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winRestore the public service docstring.
Add a concise docstring describing the partial update behavior and its conflict/not-found errors. As per coding guidelines, public service functions in
app/services/**/*.pymust have concise docstrings.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/services/language/update_language.py` around lines 10 - 16, Restore a concise public docstring on update_language describing its partial language-update behavior and documenting the conflict and not-found errors it can raise.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@app/services/language/update_language.py`:
- Around line 10-16: Restore a concise public docstring on update_language
describing its partial language-update behavior and documenting the conflict and
not-found errors it can raise.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 817955a4-57c0-4b4d-9572-21cc314bdf36
📒 Files selected for processing (1)
app/services/language/update_language.py
| from alembic import op | ||
|
|
||
| revision: str = "20260704_0002" | ||
| down_revision: str | None = "20260609_0001" |
There was a problem hiding this comment.
This still revises 20260609_0001 but main moved to 20260714_0002 since you opened it — and 20260709_0001 already revises 20260609_0001. That gives two heads after the merge and alembic upgrade head stops working. Could you re-point it to the current head and verify? ps: _0002 on a date with no _0001 looks odd, maybe rename while you are there.
Summary
Adds
PUT /api/languages/{id}to edit a language's name and/or code (withupdated_at, 409 on code conflict, 404 when missing), and — per the 2026-07 rule change — restricts the direct edit to platform admins. A manager no longer edits a language directly; a manager's edit is submitted as an edit request for a platform admin to approve, delivered by the change-requests feature (separate US) and scoped to languages linked to the manager's own projects.Changes
app/db/models/language.py(updated_at+ migration),app/models/language.py(LanguageUpdate,updated_aton the response),app/services/language/update_language.py(partial update + code-uniqueness),app/api/languages.py(PUTroute).app/api/languages.py: thePUTroute depends onrequire_platform_admin; managers receive403and must use the edit-request flow instead.Type of Change
updated_at)Testing
uv run ruff check ./uv run ruff format --check .— clean.uv run --group dev python -m pytest tests/test_language_service.py— passing (service-level).PUT /api/languages/{id}as admin updates; as a manager returns403.Summary by CodeRabbit
updated_attimestamp that changes when the record is modified.