-
-
Notifications
You must be signed in to change notification settings - Fork 422
updated mentorship_update_comments.py to not sync unlabeled modules #3007
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
Conversation
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughThe management command now filters published modules to those that have labels, logs a warning and exits early if none exist, and iterates only over labeled modules when syncing comments; modules without labels are skipped. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
ahmedxgouda
left a 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.
LGTM
kasya
left a 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.
@kart-u Thanks for getting this done so fast!
Do you think there might be a cleaner or more performant solution?
|
hello @kasya |
1a8b281
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: 0
🧹 Nitpick comments (2)
backend/apps/mentorship/management/commands/mentorship_update_comments.py (2)
46-50: Use.exists()instead of.count()for existence checks.When only checking if a queryset has any results,
.exists()is more efficient than.count()as it usesSELECT 1 ... LIMIT 1instead ofSELECT COUNT(*).🔎 Proposed refactor
- if modules_without_labels.count(): - for module in modules_without_labels: - self.stdout.write( - self.style.WARNING(f"Skipping. Module '{module.name}' has no labels.") - ) + for module in modules_without_labels: + self.stdout.write( + self.style.WARNING(f"Skipping. Module '{module.name}' has no labels.") + )Note: If the queryset is empty, the loop simply won't execute, making the
ifcheck redundant.
52-56: Use.exists()for better performance.Similar to the previous check, use
.exists()instead of.count() == 0for more efficient database queries.🔎 Proposed refactor
- if modules_with_labels.count() == 0: + if not modules_with_labels.exists(): self.stdout.write( self.style.WARNING("No published mentorship modules with labels found. Exiting.") ) return
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/apps/mentorship/management/commands/mentorship_update_comments.py
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Rajgupta36
Repo: OWASP/Nest PR: 2000
File: backend/apps/mentorship/management/commands/sync_module_issues.py:109-145
Timestamp: 2025-08-17T11:55:55.990Z
Learning: In the OWASP/Nest mentorship system, tasks are designed to be assigned to only one assignee per issue, even if GitHub issues can have multiple assignees. The sync_module_issues command correctly uses issue.assignees.first() to create one task per issue for the first assignee only.
📚 Learning: 2025-12-18T05:39:42.678Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2948
File: backend/apps/owasp/management/commands/owasp_generate_community_snapshot_video.py:40-40
Timestamp: 2025-12-18T05:39:42.678Z
Learning: In Django management commands, prefer using self.stdout.write(...) over print(...) for user-facing stdout output. This aligns with Django conventions and improves testability. When emitting messages, consider using self.stdout.write and, for styled messages, use self.style.SUCCESS/ERROR as appropriate to maintain consistent command output formatting. Apply this guideline to all Python files within any project's management/commands directory.
Applied to files:
backend/apps/mentorship/management/commands/mentorship_update_comments.py
🧬 Code graph analysis (1)
backend/apps/mentorship/management/commands/mentorship_update_comments.py (2)
backend/apps/github/api/internal/nodes/issue.py (1)
labels(50-52)backend/apps/mentorship/api/internal/nodes/mentor.py (1)
name(18-20)
🔇 Additional comments (2)
backend/apps/mentorship/management/commands/mentorship_update_comments.py (2)
58-58: Iteration logic is correct.The iteration over
modules_with_labelscorrectly implements the requirement to process only labeled modules. However, ensure the queryset filtering in lines 43-44 is fixed first.
43-44: No changes needed — the queryset filtering syntax is correct.The
labelsfield is aJSONFieldwith a default of an empty list, not a ManyToMany field. The syntaxfilter(labels=[])andexclude(labels=[])is valid and idiomatic Django ORM for JSONField comparisons. These queries correctly filter for modules where the labels field exactly matches an empty list.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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
backend/apps/mentorship/management/commands/mentorship_update_comments.py (1)
46-50: Consider logging a count instead of iterating for improved efficiency.While the current approach provides detailed visibility, iterating through all unlabeled modules just to log warnings could produce verbose output if many such modules exist. Consider logging a single message with the count of skipped modules instead.
🔎 Proposed refactor
if modules_without_labels.exists(): - for module in modules_without_labels: - self.stdout.write( - self.style.WARNING(f"Skipping. Module '{module.name}' has no labels.") - ) + count = modules_without_labels.count() + self.stdout.write( + self.style.WARNING(f"Skipping {count} module(s) with no labels.") + )
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/apps/mentorship/management/commands/mentorship_update_comments.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-18T05:39:42.678Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2948
File: backend/apps/owasp/management/commands/owasp_generate_community_snapshot_video.py:40-40
Timestamp: 2025-12-18T05:39:42.678Z
Learning: In Django management commands, prefer using self.stdout.write(...) over print(...) for user-facing stdout output. This aligns with Django conventions and improves testability. When emitting messages, consider using self.stdout.write and, for styled messages, use self.style.SUCCESS/ERROR as appropriate to maintain consistent command output formatting. Apply this guideline to all Python files within any project's management/commands directory.
Applied to files:
backend/apps/mentorship/management/commands/mentorship_update_comments.py
🔇 Additional comments (3)
backend/apps/mentorship/management/commands/mentorship_update_comments.py (3)
52-56: LGTM! Good defensive programming.The early exit check prevents unnecessary processing when no labeled modules exist, and the warning message clearly communicates the reason for exiting.
58-58: Change correctly implements the PR objective.The iteration now processes only labeled modules, which achieves the goal of skipping unlabeled modules. The existing processing logic for labeled modules is preserved, ensuring backward compatibility.
43-44: Thelabels=[]filter syntax is correct for the JSONField.The
labelsfield is defined asmodels.JSONField(blank=True, default=list), so the filtering logic withexclude(labels=[])andfilter(labels=[])works correctly to separate modules by label presence. This pattern is consistent with other uses in the codebase.The only minor optimization to consider: these two queries against the same base queryset could be combined into a single query using annotation or conditional aggregation to reduce database hits, though this is unlikely to be a bottleneck for typical dataset sizes.
| modules_without_labels = published_modules.filter(labels=[]) | ||
|
|
||
| if modules_without_labels.exists(): | ||
| for module in modules_without_labels: | ||
| self.stdout.write( | ||
| self.style.WARNING(f"Skipping. Module '{module.name}' has no labels.") | ||
| ) |
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.
I think there's still a better solution...
Do we really need to see this printed out? Do we care about this info at all? 🤔 This will require more computation and will slow down sync a little bit. Or a lot, depending on number of modules available.
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.
Yes you are absolutely right , I had some doubts about this as well. It was included to satisfy a issue requirement, but if the output isn’t useful , I’m fine with removing it
|
…WASP#3007) * updated mentorship_update_comments.py to not sync unlabeled modules * updated code * updated code * updated:removed logs for unlabelled
Proposed change
Resolves #2860
Added a condition to skip sync for unlabeled modules.
Checklist
make check-testlocally and all tests passed