Skip to content

Conversation

x753
Copy link
Contributor

@x753 x753 commented Jun 2, 2025

Consolidate team creation logic by calling Team.create() from the team creation service
Remove the namespace creation logic from Team.create()

The removal of
Namespace.objects.create(name=name, team=team)
will fix the issue where users can log in, automatically create a team and namespace with the old package upload form, then disband their team leaving the namespace stuck unable to be used again.

Consolidate team creation logic by calling Team.create() from the team
creation service
Remove the namespace creation logic from Team.create()
Copy link

codecov bot commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.22%. Comparing base (ea4437f) to head (f4be45d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1153      +/-   ##
==========================================
+ Coverage   93.20%   93.22%   +0.01%     
==========================================
  Files         324      324              
  Lines        9931     9927       -4     
  Branches      923      922       -1     
==========================================
- Hits         9256     9254       -2     
+ Misses        554      552       -2     
  Partials      121      121              

☔ 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.

Comment on lines -188 to +189
existing_ns = Namespace.objects.filter(name__iexact=name).first()
if existing_ns:
raise ValidationError("Namespace with the Teams name exists")
else:
team = cls.objects.create(name=name, **kwargs)
Namespace.objects.create(name=name, team=team)
return team
team = cls.objects.create(name=name, **kwargs)
return team
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not entirely sure why we want to move or remove the Namespace validation from the Team.create() function. Can you clarify the motivation behind this refactor?

I’m wondering why we’re using a @classmethod directly on the model, instead of the more idiomatic Django pattern of defining custom creation logic on the model's manager. Using the manager would keep the model cleaner and make creation more consistent with Django conventions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace validation is redundant because Team.create() will always call save() which will call validate() which also has namespace validation.

I'm pretty sure we could just remove Team.create() entirely and use Team.objects.create() like normal, I just tried to keep my changes minimal since it's used in a lot of tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that the namespace validation in Team.create() was redundant since it's already handled in validate(). However, now that the custom validation logic has been removed, the Team.create() method itself has become redundant, it's just a wrapper around Team.objects.create() with no added functionality.

I think the cleanest solution would be to remove the Team.create() classmethod entirely and update all call sites to use the standard Team.objects.create(). Otherwise we're just creating technical debt, and using Team.objects.create() is more in line with Django conventions.

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.

2 participants