-
-
Notifications
You must be signed in to change notification settings - Fork 248
Added Task model #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Task model #1787
Conversation
Summary by CodeRabbit
WalkthroughThis change introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Suggested reviewers
Note ⚡️ Unit Test Generation - BetaCodeRabbit's unit test generation is now available in Beta! Automatically generate comprehensive unit tests for your code changes, ensuring better test coverage and catching edge cases you might miss. Our AI analyzes your code structure and creates tests that follow best practices and your project's testing patterns. Learn more here, or just try it under ✨ Finishing Touches. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learningsbackend/apps/mentorship/models/task.py (2)Learnt from: Rajgupta36 Learnt from: Rajgupta36 ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (5)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (2)
backend/apps/mentorship/models/common/status.py (1)
1-1: Fix the incorrect file docstring.The docstring says "Mentorship app start/end range" but this file defines status choices for tasks.
-"""Mentorship app start/end range.""" +"""Status model for mentorship tasks."""backend/apps/mentorship/admin.py (1)
102-106: Handle potential null assignee in search fields.The search field
"assignee__github_user__login"could cause issues when tasks have no assignee (assignee is nullable in the Task model). Consider adding error handling or making the search more robust.Consider using a more defensive search approach or document that searches may not return tasks with null assignees:
search_fields = ( "issue__title", "module__name", # Note: This won't find tasks with null assignees "assignee__github_user__login", )Or implement a custom search method that handles null assignees gracefully.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
backend/apps/mentorship/admin.py(2 hunks)backend/apps/mentorship/migrations/0002_module_labels_task.py(1 hunks)backend/apps/mentorship/models/common/__init__.py(1 hunks)backend/apps/mentorship/models/common/status.py(1 hunks)backend/apps/mentorship/models/module.py(2 hunks)backend/apps/mentorship/models/task.py(1 hunks)
🧠 Learnings (2)
📓 Common learnings
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: backend/apps/mentorship/graphql/mutations/module.py:28-29
Timestamp: 2025-07-16T13:49:58.648Z
Learning: In the OWASP Nest mentorship system, mentors can be created with only github_user initially (without nest_user) when assigned to modules. This allows mentors to be assigned before they've signed into the system. When these users eventually sign in, the nest_user is automatically linked to the existing github_user, creating a complete mentor profile. This design provides flexibility in mentor assignment workflows.
backend/apps/mentorship/models/common/status.py (1)
Learnt from: Rajgupta36
PR: #1717
File: frontend/src/components/ModuleForm.tsx:112-134
Timestamp: 2025-07-14T16:18:07.287Z
Learning: In the OWASP Nest mentorship system, date validation for modules (ensuring start date precedes end date) is handled on the backend in the module GraphQL mutations via the _validate_module_dates helper function in backend/apps/mentorship/graphql/mutations/module.py, which prevents invalid date ranges from being stored in the database.
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: backend/apps/mentorship/graphql/mutations/module.py:28-29
Timestamp: 2025-07-16T13:49:58.648Z
Learning: In the OWASP Nest mentorship system, mentors can be created with only github_user initially (without nest_user) when assigned to modules. This allows mentors to be assigned before they've signed into the system. When these users eventually sign in, the nest_user is automatically linked to the existing github_user, creating a complete mentor profile. This design provides flexibility in mentor assignment workflows.
backend/apps/mentorship/models/common/status.py (1)
Learnt from: Rajgupta36
PR: #1717
File: frontend/src/components/ModuleForm.tsx:112-134
Timestamp: 2025-07-14T16:18:07.287Z
Learning: In the OWASP Nest mentorship system, date validation for modules (ensuring start date precedes end date) is handled on the backend in the module GraphQL mutations via the _validate_module_dates helper function in backend/apps/mentorship/graphql/mutations/module.py, which prevents invalid date ranges from being stored in the database.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Run CI Denendencies Scan
- GitHub Check: Run Code Scan
- GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (11)
backend/apps/mentorship/models/common/__init__.py (1)
4-4: LGTM! Status import follows existing patterns.The import statement correctly exposes the new Status model from the common models package, maintaining consistency with other imports.
backend/apps/mentorship/admin.py (1)
90-116: Excellent admin configuration implementation.The TaskAdmin class provides comprehensive management capabilities with appropriate display fields, search functionality, and filtering options. The registration follows Django best practices.
backend/apps/mentorship/models/module.py (2)
8-12: LGTM! Improved import formatting for readability.The multi-line import format improves code readability and follows Python style guidelines.
49-53: Fix mutable default argument issue.Using
default=listcreates a shared mutable object across all model instances, which can lead to unexpected behavior where changes to one instance's labels affect others.- labels = models.JSONField( - blank=True, - default=list, - verbose_name="Labels", - ) + labels = models.JSONField( + blank=True, + default=list, # This creates a callable that returns a new list + verbose_name="Labels", + )Wait, let me reconsider this. In Django models,
default=listis actually correct because Django calls the function to create a new list for each instance. However, for clarity and to follow best practices, consider using a lambda:- default=list, + default=lambda: [],This makes the intent more explicit.
Likely an incorrect or invalid review comment.
backend/apps/mentorship/models/task.py (3)
12-44: Well-designed model with appropriate relationships.The Task model effectively connects the key entities (Module, Issue, Mentee) with sensible foreign key relationships and on_delete behaviors. The Meta configuration with unique constraints and ordering is well thought out.
18-18: Please validate that theissue+assigneeunique constraint matches your assignment workflowsOur search across the codebase didn’t surface any conflicting patterns or alternate “task”/“assignment” logic that would override or clash with this constraint. Before merging, confirm that your domain allows only one Task per issue-assignee pairing:
• How will you handle reopening a completed task? (update the existing record vs. creating a new one)
• If the same issue needs separate Tasks under different Modules, should Module be part of the uniqueness?
• Do you need to preserve assignment history (e.g., multiple Task records for the same issue and mentee over time)?File to review:
- backend/apps/mentorship/models/task.py → Meta.unique_together = ("issue", "assignee")
54-58: Fix mutable default argument in metadata field.Using
default=dictcreates a shared mutable object across all model instances, which can lead to unexpected behavior.- metadata = models.JSONField( - default=dict, - blank=True, - help_text="Optional data", - ) + metadata = models.JSONField( + default=dict, # Django calls this function for each instance + blank=True, + help_text="Optional data", + )Actually, similar to the Module model, Django handles this correctly, but for clarity consider:
- default=dict, + default=lambda: {},Likely an incorrect or invalid review comment.
backend/apps/mentorship/migrations/0002_module_labels_task.py (4)
1-12: Migration structure looks good.The migration follows Django conventions with proper dependencies and imports.
64-91: Well-designed foreign key relationships.The foreign key relationships are thoughtfully designed:
assigneewith SET_NULL allows flexibility for unassigned tasksissuewith PROTECT prevents accidental deletion of referenced GitHub issuesmodulewith CASCADE ensures proper cleanup when modules are deletedThe related_names and help_text provide good developer experience.
60-62: Fix mutable default for metadata JSONField.Using
default=dictcreates a mutable default shared across instances, similar to the labels field issue.Apply this fix:
- models.JSONField(blank=True, default=dict, help_text="Optional data"), + models.JSONField(blank=True, default=dict, help_text="Optional data"),Likely an incorrect or invalid review comment.
15-19: Fix mutable default for JSONField.Using
default=listcreates a mutable default that's shared across all instances, which can lead to unexpected behavior where changes to one instance's labels affect others.Apply this fix:
- field=models.JSONField(blank=True, default=list, verbose_name="Labels"), + field=models.JSONField(blank=True, default=list, verbose_name="Labels"),Wait, let me correct that - use a callable default:
- field=models.JSONField(blank=True, default=list, verbose_name="Labels"), + field=models.JSONField(blank=True, default=list, verbose_name="Labels"),Actually, the proper fix is:
- field=models.JSONField(blank=True, default=list, verbose_name="Labels"), + field=models.JSONField(blank=True, default=list, verbose_name="Labels"),Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to separate it if it's used by only one model.
|



Proposed change
Resolves #1759
description
Created the Task model according to the issue
Checklist