Dev#22
Conversation
…nization-model feat: add template field for organization model
…etter fix: prevent crashing using itemgetter
There was a problem hiding this comment.
Code Review
This pull request adds a template field to the Organization model and updates the initialization logic to handle organization templates. Key feedback includes a critical bug where the --org-template argument is missing from the management command's parser, which will cause the service to fail on startup. Other issues identified include the failure to persist the template value to the database during organization creation and a potential KeyError when accessing user emails in the authentication service.
| return { | ||
| "org_name": kwargs.get("org_name") or os.getenv("ORG_NAME"), | ||
| "org_slug": kwargs.get("org_slug") or os.getenv("ORG_SLUG"), | ||
| "org_template": kwargs.get("org_template") or os.getenv("ORG_TEMPLATE"), |
| # Publish organization event | ||
| self._publish_org_event(org_id, org_slug, org_name, result) | ||
| self._send_celery_task(org_id, org_name, org_slug, user) | ||
| self._send_celery_task(org_id, org_name, org_slug, org_template, user) |
There was a problem hiding this comment.
| template = models.CharField( | ||
| max_length=256, choices=OrganizationTemplate.choices, blank=True, null=True | ||
| ) |
| given_name = user_info_dict.get("given_name", "") | ||
| family_name = user_info_dict.get("family_name", "") | ||
| email = user_info_dict["email"] |
There was a problem hiding this comment.
Accessing email directly from user_info_dict may raise a KeyError if the key is missing from the provider's response. It is safer to use .get() and handle the missing value explicitly, for example by raising a ValidationError.
given_name = user_info_dict.get("given_name", "")
family_name = user_info_dict.get("family_name", "")
email = user_info_dict.get("email")
if not email:
raise ValidationError({"email": f"Email not provided by {provider}."})
What?
Why?
How?
Testing?
Anything Else?