HumanSignal/label-studio · error · CommandError
No projects found for organization
Error message
No projects found for organization {organization_id} What it means
The `recalculate_task_counters` management command was invoked with --organization <id>, but no Projects exist for that organization. CommandError is raised so the operator knows the org has nothing to recalculate rather than exiting silently with zero output.
Solutions
- Verify the organization ID via Django shell (Organization.objects.filter(id=<id>)) and that it has projects (Project.objects.filter(organization_id=<id>).count())
- If you intended one specific project, use --project <id> instead
- Check that you are connected to the expected database/environment
- If the org legitimately has no projects, there is nothing to recalculate; no action needed
Example fix
// before python manage.py recalculate_task_counters --organization 999 # org has no projects // after python manage.py recalculate_task_counters --organization 1 # org confirmed to own projects
Defensive patterns
Strategy: validation
Validate before calling
from projects.models import Organization, Project
def assert_org_has_projects(org_id):
if not Project.objects.filter(organization_id=org_id).exists():
org = Organization.objects.filter(id=org_id).first()
raise SystemExit(f"Organization {org_id} ({org}) has no projects; nothing to recalculate") Type guard
def org_has_projects(org_id) -> bool:
from tasks.models import Project
return Project.objects.filter(organization_id=org_id).exists() Try / catch
from django.core.management import call_command
from django.core.management.base import CommandError
try:
call_command('recalculate_task_counters', organization=str(org_id))
except CommandError as e:
logger.warning("no recalculation performed: %s", e) Prevention
- Verify org ID and its project count before running
- Use the internal numeric organization ID, not external/SSO identifiers
- Check DB connection settings when IDs 'mysteriously' don't exist
- Accept that empty orgs legitimately produce this; skip them in orchestration scripts
When it happens
Trigger: Running `recalculate_task_counters --organization <id>` where the org ID is wrong, belongs to another environment, or the organization exists but has zero projects (or all projects were deleted).
Common situations: Using an organization ID from a different Label Studio instance; passing the org's external/SSO identifier instead of the internal numeric ID; an empty organization with no projects; wrong DB connection pointing at a fresh install.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Project not found
- annotation_ser.errors
- batch_validation_errors
- Can't deserialize tasks due to
- Can't find Organization by welcome URL
AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29).
Data as JSON: /api/errors/4231d9c929cadd1b.
Report an issue: GitHub.
Appendix: source
Thrown at label_studio/tasks/management/commands/recalculate_task_counters.py:69
.count()
)
def handle(self, *args, **options):
project_id = options.get('project')
organization_id = options.get('organization')
dry_run = options.get('dry_run')
if not project_id and not organization_id:
raise CommandError('Provide --project <id> or --organization <id>')
if project_id:
projects = Project.objects.filter(id=project_id)
if not projects.exists():
raise CommandError(f'Project {project_id} not found')
else:
projects = Project.objects.filter(organization_id=organization_id)
if not projects.exists():
raise CommandError(f'No projects found for organization {organization_id}')
for project in projects:
drifted_before = self._drifted_count(project)
self.stdout.write(
f'Project {project.id} ({project.title!r}): {drifted_before} task(s) with drifted counters'
)
if dry_run:
continue
# Recompute counters AND is_labeled (run_sync=True runs the canonical
# update_tasks_counters + bulk_update_stats_project_tasks inline, batched
# in transactions), so is_labeled can't be left stale after the counters change.
updated = project.update_tasks_counters_and_is_labeled(Task.objects.filter(project=project), run_sync=True)
drifted_after = self._drifted_count(project)
self.stdout.write(
self.style.SUCCESS(
f'Project {project.id}: recalculated {updated} task(s); 'View on GitHub (pinned to 0b49e9b539)