Fix some aspects of endpoint#105
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a typed error taxonomy and helpers, integrates structured error payloads into serializer validation, views, services (git/file removal and process_submodule/process_all), and Celery tasks, and updates tests and an example env var to assert and consume these typed errors. ChangesStructured Error Handling Integration
Sequence Diagram(s)sequenceDiagram
participant View as AddOrUpdateView.post
participant Serializer as AddOrUpdateRequestSerializer
participant Task as boost_add_or_update_task
participant Service as BoostComponentService
participant Errors as boost_weblate.endpoint.errors
View->>Serializer: is_valid(raise_exception=True)
alt Invalid request
Serializer->>Errors: map DRF ErrorDetail -> BoostEndpointErrorCode
Errors-->>Serializer: structured error dicts
Serializer-->>View: raises ValidationError with structured_errors
View-->>Client: HTTP 400 { "errors": [...] }
else Valid request
View->>Task: apply_async() / start
Task->>Service: process_all(temp_dir)
Service->>Errors: append_error() for per-submodule failures
Service-->>Task: result with structured errors
Task->>Errors: wrap_task_error() on unexpected exception
Errors-->>Task: BoostEndpointError
Task-->>Broker: raise BoostEndpointError (typed)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 @.env.example:
- Line 50: There is a duplicate environment variable definition for
WEBLATE_REGISTRATION_OPEN; remove the redundant entry so the variable is defined
only once (keep the intended value and delete the other line), ensuring the
single remaining WEBLATE_REGISTRATION_OPEN entry reflects the correct
boolean/value used by the application.
In `@src/boost_weblate/endpoint/serializers.py`:
- Around line 87-115: The _flatten_field_errors function in
AddOrUpdateRequestSerializer currently stringifies DRF ErrorDetail objects which
breaks stable error-code mapping; modify _flatten_field_errors to propagate each
error's drf_code (use getattr(err, "code", None)) and return tuples like
(subfield, message, drf_code) instead of just (subfield, message), update any
call sites (including _code_for_drf_error) to accept the new triplet shape, and
change _code_for_drf_error to map DRF codes directly (e.g., ListField codes
"not_a_list" and "empty" → INVALID_SUBMODULE_LIST, missing field "required" →
REQUIRED_FIELD) rather than doing substring matching on message text. Ensure
nested branches (lists, dicts, ErrorDetail instances) preserve and propagate the
drf_code and adjust tests/consumers to handle the new tuple form.
In `@src/boost_weblate/endpoint/services.py`:
- Around line 131-138: The code currently runs subprocess.run(...) and uses
git_status.stdout without checking git_status.returncode, so add an explicit
check after the subprocess call (inspect git_status.returncode) and treat any
non-zero return code as a failure: log the error including git_status.stderr and
git_status.returncode (using the existing logger), and abort/raise (do not
proceed with DB deletion) when returncode != 0; update the block around the
subprocess.run invocation and the git_status variable usage to enforce this
explicit failure path (reference: git_status, subprocess.run call that uses
["git", "-C", base_path, "status", "--porcelain"]).
- Around line 146-156: The git commit call in subprocess.run (the one building
args with "git", "-C", base_path, "commit", "-m", f"Remove translation files for
deleted component: {name}", "--author", author) is not path-scoped and may
include unrelated staged changes; change the command to explicitly limit the
commit to the removed translation file paths by appending "--" followed by the
list of removed file paths (e.g., a variable like removed_paths or
removed_files) to the args passed to subprocess.run so only those files are
committed (ensure you pass the exact relative paths as arguments after the
"--").
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 29945e07-71dd-402e-89f4-18b3aa1b5a2c
📒 Files selected for processing (10)
.env.examplesrc/boost_weblate/endpoint/errors.pysrc/boost_weblate/endpoint/serializers.pysrc/boost_weblate/endpoint/services.pysrc/boost_weblate/endpoint/tasks.pysrc/boost_weblate/endpoint/views.pytests/endpoint/test_errors.pytests/endpoint/test_serializers.pytests/endpoint/test_services.pytests/endpoint/test_views.py
henry0816191
left a comment
There was a problem hiding this comment.
docs/boost-endpoint-api.md still documents the old error shapes
|
@coderabbitai, resume |
|
✅ Action performedReviews resumed. |
Close #99, close #103, close #102.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation
Chores