Add steward score reasons#829
Conversation
📝 WalkthroughWalkthroughAdds an optional ChangesFeature Candidate Score Reason Field
Sequence Diagram(s)sequenceDiagram
actor Reviewer
participant StewardFeatureReviews
participant stewardAPI
participant FeatureCandidateReviewViewSet
participant FeatureCandidateScore
Reviewer->>StewardFeatureReviews: click score option
StewardFeatureReviews->>StewardFeatureReviews: updateScoreDraft(candidate, {score})
Reviewer->>StewardFeatureReviews: type in Reason textarea
StewardFeatureReviews->>StewardFeatureReviews: updateScoreDraft(candidate, {reason})
Reviewer->>StewardFeatureReviews: click "Save opinion"
StewardFeatureReviews->>stewardAPI: scoreFeatureReviewCandidate(id, score, reason)
stewardAPI->>FeatureCandidateReviewViewSet: POST /score/ {score, reason}
FeatureCandidateReviewViewSet->>FeatureCandidateScore: update_or_create(score, reason)
FeatureCandidateScore-->>FeatureCandidateReviewViewSet: saved
FeatureCandidateReviewViewSet-->>stewardAPI: {submission, score, reason}
stewardAPI-->>StewardFeatureReviews: response
StewardFeatureReviews->>StewardFeatureReviews: update candidate own_score + own_score_reason, increment progress
StewardFeatureReviews-->>Reviewer: success toast
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@backend/stewards/models.py`:
- Around line 45-49: The `reason` TextField in the model is unconstrained while
the API serializer enforces a max_length of 2000 characters, allowing non-API
writes to persist oversized values. Add a max_length=2000 parameter to the
`reason` field definition in the model to enforce the constraint at the
model/schema boundary and ensure consistency with the API contract defined in
the serializer.
In `@backend/stewards/tests.py`:
- Around line 269-274: The assertion on line 274 is too generic for the test
case on line 269 which has a valid score but invalid reason (exceeding 2000
characters). Replace the weak assertion `self.assertTrue('score' in
response.data or 'reason' in response.data)` with a more specific check that
validates only the 'reason' key is present in response.data for that particular
subTest payload. This ensures the test tightly verifies that the error is
specifically about the reason field validation failure, not accidentally
accepting other field errors.
In `@frontend/src/routes/StewardFeatureReviews.svelte`:
- Line 204: The showError function call is receiving potentially non-string
values like arrays from DRF field errors, which results in unreadable toast
messages. Before passing the error value to the showError function, normalize it
to a readable string format by converting the selected error field (detail,
score, reason, or the fallback message) to a string. You may want to use
JSON.stringify for complex objects or implement a helper function that converts
various error types into human-readable messages, ensuring that the toast always
displays legible text regardless of the error structure.
🪄 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: ASSERTIVE
Plan: Pro Plus
Run ID: 20ad1a87-b230-4673-a558-fdc7f5eebd49
📒 Files selected for processing (8)
backend/stewards/admin.pybackend/stewards/migrations/0012_feature_candidate_score_reason.pybackend/stewards/models.pybackend/stewards/serializers.pybackend/stewards/tests.pybackend/stewards/views.pyfrontend/src/lib/api.jsfrontend/src/routes/StewardFeatureReviews.svelte
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)
backend/stewards/models.py (1)
45-50: 🗄️ Data Integrity & Integration | 🟠 MajorAdd a
CheckConstraintfor thereasonfield's max length to enforce database-level validation.The
max_length=2000on line 46 only provides application-level validation. Direct ORM writes or bulk imports can bypass this and persist oversized values. Add aCheckConstrainton thereasonfield in the model'sMeta.constraintslist, and create a corresponding migration to enforce this at the database level.🤖 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 `@backend/stewards/models.py` around lines 45 - 50, The reason field has application-level max_length validation but lacks database-level enforcement, allowing direct ORM writes or bulk imports to bypass this constraint. Add a CheckConstraint in the Meta.constraints list of the model class that limits the reason field to a maximum length of 2000 characters using a character length condition, then create and apply a Django migration to enforce this constraint at the database level.
🤖 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 `@backend/stewards/models.py`:
- Around line 45-50: The reason field has application-level max_length
validation but lacks database-level enforcement, allowing direct ORM writes or
bulk imports to bypass this constraint. Add a CheckConstraint in the
Meta.constraints list of the model class that limits the reason field to a
maximum length of 2000 characters using a character length condition, then
create and apply a Django migration to enforce this constraint at the database
level.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5dc1efaf-0384-4362-84a1-3c0380341dfd
📒 Files selected for processing (4)
backend/stewards/migrations/0012_feature_candidate_score_reason.pybackend/stewards/models.pybackend/stewards/tests.pyfrontend/src/routes/StewardFeatureReviews.svelte
Summary
Adds an optional reason field to steward feature candidate scores so each score can capture what stood out about the project.
Updates the feature scoring view to let stewards draft a score and reason before saving.
Includes API, serializer, admin, migration, and coverage updates for storing and returning each steward's own reason.
Summary by CodeRabbit
New Features
Bug Fixes
Tests