Skip to content

Conversation

@Roffenlund
Copy link
Contributor

Add validation checks for checking if Team and Namespace already exists to create_team service in order to catch these potential validation errors before reaching the model.

Refs. TS-2739

Add validation checks for checking if Team and Namespace already exists
to create_team service in order to catch these potential validation
errors before reaching the model.

Refs. TS-2739
@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2025

Walkthrough

The create_team function in django/thunderstore/api/cyberstorm/services/team.py now includes pre-validation checks before team creation. The function imports ValidationError and the Namespace model, then validates that neither a team nor namespace with the provided name (case-insensitive) already exists. If either exists, a ValidationError is raised, providing early exit behavior. The function signature and return type remain unchanged.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change of adding validation checks to the create_team service, matching the PR’s objective and summarizing the main change clearly.
Description Check ✅ Passed The description accurately explains that the PR adds validation checks for existing Teams and Namespaces in the create_team service to prevent model-level errors, which aligns with the actual changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch team-creation-validation-checks

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.81%. Comparing base (5f7c539) to head (fa51e85).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1192   +/-   ##
=======================================
  Coverage   92.81%   92.81%           
=======================================
  Files         337      337           
  Lines       10355    10361    +6     
  Branches      937      939    +2     
=======================================
+ Hits         9611     9617    +6     
  Misses        617      617           
  Partials      127      127           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a 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)
django/thunderstore/api/cyberstorm/services/team.py (1)

25-28: Consider whether service-layer validation duplication is necessary.

The validation checks you've added duplicate the logic in Team.validate() (lines 127-131 in team.py), which is already called via Team.create() → save() → validate() at line 30. While your PR objectives state this is intentional to catch errors before the model layer, consider whether:

  1. Relying solely on the model validation would be sufficient
  2. If service-layer validation is required, extracting the validation logic into a shared method would reduce duplication and maintenance burden

The current implementation works correctly but violates DRY. The trade-off is defense-in-depth vs. code duplication.

Static analysis note: Ruff flags the inline error messages (TRY003). If you proceed with service-layer validation, consider extracting messages to constants or custom exception classes for consistency, though this is consistent with the existing model-layer code.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f7c539 and fa51e85.

📒 Files selected for processing (1)
  • django/thunderstore/api/cyberstorm/services/team.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
django/thunderstore/api/cyberstorm/services/team.py (4)
django/thunderstore/account/models/service_account.py (1)
  • ServiceAccount (20-93)
django/thunderstore/core/exceptions.py (1)
  • PermissionValidationError (4-7)
django/thunderstore/repository/models/team.py (2)
  • Team (92-380)
  • TeamMember (42-79)
django/thunderstore/repository/models/namespace.py (1)
  • Namespace (10-44)
🪛 Ruff (0.14.0)
django/thunderstore/api/cyberstorm/services/team.py

26-26: Avoid specifying long messages outside the exception class

(TRY003)


28-28: Avoid specifying long messages outside the exception class

(TRY003)

⏰ 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: Build docker image
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build docker image
🔇 Additional comments (1)
django/thunderstore/api/cyberstorm/services/team.py (1)

1-1: LGTM!

Imports are correct and necessary for the validation logic.

Also applies to: 8-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants