HumanSignal/label-studio · error · KeyError
Can't find Organization by welcome URL: {url}
Error message
Can't find Organization by welcome URL: {url} What it means
Organization.find_by_invite_url parses the last path segment of a welcome/invite URL as a token and raises KeyError when the token is empty. Note it does NOT catch DoesNotExist — an invalid non-empty token still raises Organization.DoesNotExist from .get(); this KeyError only fires for URLs whose stripped value has no trailing segment.
Source
Thrown at label_studio/organizations/models.py:143
@classmethod
def find_by_user(cls, user, check_deleted=False):
memberships = OrganizationMember.objects.filter(user=user).prefetch_related('organization')
if not memberships.exists():
raise ValueError(f'No memberships found for user {user}')
membership = memberships.first()
if check_deleted:
return (membership.organization, True) if membership.deleted_at else (membership.organization, False)
return membership.organization
@classmethod
def find_by_invite_url(cls, url):
token = url.strip('/').split('/')[-1]
if len(token):
return Organization.objects.get(token=token)
else:
raise KeyError(f"Can't find Organization by welcome URL: {url}")
def has_user(self, user):
return self.users.filter(pk=user.pk).exists()
def has_deleted(self, user):
return OrganizationMember.objects.filter(user=user, organization=self, deleted_at__isnull=False).exists()
def has_project_member(self, user):
return self.projects.filter(members__user=user).exists()
def has_permission(self, user):
return OrganizationMember.objects.filter(user=user, organization=self, deleted_at__isnull=True).exists()
def add_user(self, user):
if _workforce_closure_blocked(user):
# A closed identity must never gain a NEW membership anywhere — this is the one
# chokepoint every membership creation goes through (invites, SCIM, SAML, LDAP, admin).
logger.warning(View on GitHub (pinned to 0b49e9b539)
Solutions
- Inspect the URL — it must end with a non-empty token segment
- Re-generate the invite link from the organization settings page
- Check the org's token field is populated in the DB (Organization.token)
- Verify the env/config that injects the token into the welcome URL
Example fix
// before
org = Organization.find_by_invite_url(invite_url) # invite_url may be ''
// after
if not invite_url or not invite_url.strip('/').split('/')[-1]:
raise ImproperlyConfigured('Invite URL missing token')
org = Organization.find_by_invite_url(invite_url) Defensive patterns
Strategy: validation
Validate before calling
token = url.strip('/').split('/')[-1] if url else ''
if not token:
raise ImproperlyConfigured('invite URL has no token segment') Try / catch
try:
org = Organization.find_by_invite_url(url)
except KeyError:
... # empty token — fix URL config
except Organization.DoesNotExist:
... # token not recognized — link expired/regenerated Prevention
- Validate invite URL templates in env settings at startup
- Never trim trailing path segments from invite links
- Ensure Organization.token is generated on org creation
- Log full URL on failure to diagnose config issues
When it happens
Trigger: Calling Organization.find_by_invite_url with an empty string, '', a URL like 'https://host/invite' with nothing after the last slash, or a URL that reduces to no token after strip('/').split('/').
Common situations: Misconfigured WELCOME_URL / invite link template missing the token; env var or org setting blank; copying the invite base URL without the token; trailing formatting stripping the token client-side.
Related errors
- Can't find Project by invite URL: {url}
- LABEL_STUDIO_HOST must be a subpath if DOMAIN_FROM_REQUEST i
- SECURE_PROXY_SSL_HEADER must be configured as "<header>,<val
- Incorrect value type in key "{key}" = "{value}". It should b
- Incorrect value type in key "{key}" = "{value}". It should b
AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29).
Data as JSON: /api/errors/6f3b0715d73be30c.
Report an issue: GitHub.