{"record":{"id":"33ba1bbd445c7063","repo":"HumanSignal/label-studio","slug":"no-state-model-found-for-entity-meta-model-name","errorCode":null,"errorMessage":"No state model found for {entity._meta.model_name} when getting current state","messagePattern":"No state model found for (.+?) when getting current state","errorType":"exception","errorClass":"StateManagerError","httpStatus":null,"severity":"error","filePath":"label_studio/fsm/state_manager.py","lineNumber":158,"sourceCode":"        # Try cache first\n        cached_state = fsm_cache.get(cache_key)\n        if cached_state is not None:\n            logger.info(\n                'FSM: Cache hit',\n                extra={\n                    'event': 'fsm.cache_hit',\n                    'entity_type': entity._meta.label_lower,\n                    'entity_id': entity.pk,\n                    'organization_id': CurrentContext.get_organization_id(),\n                    'state': cached_state,\n                },\n            )\n            return cached_state\n\n        # Query database using state model registry\n        state_model = get_state_model_for_entity(entity)\n        if not state_model:\n            raise StateManagerError(f'No state model found for {entity._meta.model_name} when getting current state')\n\n        try:\n            current_state = state_model.get_current_state_value(entity)\n\n            # Cache result\n            if current_state is not None:\n                fsm_cache.set(cache_key, current_state, cls.CACHE_TTL)\n                logger.info(\n                    'FSM: Cache miss',\n                    extra={\n                        'event': 'fsm.cache_miss',\n                        'entity_type': entity._meta.label_lower,\n                        'entity_id': entity.pk,\n                        'organization_id': CurrentContext.get_organization_id(),\n                    },\n                )\n\n            return current_state","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/fsm/state_manager.py#L140-L176","documentation":"StateManager.get_current_state_value looks up the entity's state model via the registry (get_state_model_for_entity). When no state model has been registered for the entity's Django model, it raises StateManagerError naming the model. StateManager can only read current state through a registered state model's get_current_state_value, so an unregistered entity is unsupported rather than simply 'stateless'.","triggerScenarios":"Calling get_current_state_value (directly or via transition_state/warm_cache) with an entity whose model was never registered via the state-model registry — e.g., a model without FSM registration, a proxy/swapped model whose label doesn't match the registration key, or code running before registry population (imports/app-init order).","commonSituations":"Adding FSM calls to a new model but forgetting the registry.register decorator; model swaps or migrations changing model_name; enterprise/community version skew where the state model registration lives in a package not installed; calling transitions in management commands before Django app registry is ready.","solutions":["Register a state model for the entity in fsm/registry (state_model_registry.register) or check the entity against state_model_registry.get_all_models() before calling.","Verify the entity type is actually FSM-managed; guard calls with a registry lookup for entity._meta.model_name.","Check app/import ordering so registrations run before any StateManager call.","If on Label Studio Open Source, confirm the entity's state model isn't Enterprise-only (LSE) — install/enable the component that registers it."],"exampleFix":"// before\nstate = StateManager.get_current_state_value(task)  # raises: No state model found for task\n\n// after\nfrom fsm.registry import get_state_model_for_entity\nif get_state_model_for_entity(task) is not None:\n    state = StateManager.get_current_state_value(task)\nelse:\n    state = None  # entity is not FSM-managed","handlingStrategy":"type-guard","validationCode":"from fsm.registry import get_state_model_for_entity\n\nif get_state_model_for_entity(entity) is None:\n    # entity is not FSM-managed; skip state lookup\n    ...","typeGuard":"def is_fsm_managed(entity) -> bool:\n    from fsm.registry import get_state_model_for_entity\n    try:\n        return get_state_model_for_entity(entity) is not None\n    except Exception:\n        return False","tryCatchPattern":"from fsm.state_manager import StateManagerError\ntry:\n    state = StateManager.get_current_state_value(entity)\nexcept StateManagerError as e:\n    if 'No state model found' in str(e):\n        state = None  # entity has no FSM support\n    else:\n        raise","preventionTips":["Check the registry before calling StateManager for any entity type","Register state models at app startup so they exist before any lookup","Keep registry keys in sync with model renames (_meta.model_name)"],"tags":["fsm","registry","state-manager","django"],"backgroundTag":"unregistered-entity-state-model","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}