{"record":{"id":"8eb088838b6c5959","repo":"HumanSignal/label-studio","slug":"error-getting-current-state-e","errorCode":null,"errorMessage":"Error getting current state: {e}","messagePattern":"Error getting current state: (.+?)","errorType":"exception","errorClass":"StateManagerError","httpStatus":null,"severity":"error","filePath":"label_studio/fsm/state_manager.py","lineNumber":190,"sourceCode":"                        'organization_id': CurrentContext.get_organization_id(),\n                    },\n                )\n\n            return current_state\n\n        except Exception as e:\n            logger.error(\n                'FSM: Error getting current state',\n                extra={\n                    'event': 'fsm.get_state_error',\n                    'entity_type': entity._meta.label_lower,\n                    'entity_id': entity.pk,\n                    'organization_id': CurrentContext.get_organization_id(),\n                    'error': str(e),\n                },\n                exc_info=True,\n            )\n            raise StateManagerError(f'Error getting current state: {e}') from e\n\n    @classmethod\n    def get_current_state_object(cls, entity: Model) -> BaseState:\n        \"\"\"\n        Get current state object with full audit information.\n\n        Args:\n            entity: The entity to get current state object for\n\n        Returns:\n            Latest BaseState instance\n\n        Raises:\n            StateManagerError: If no state model found\n        \"\"\"\n        state_model = get_state_model_for_entity(entity)\n        if not state_model:\n            raise StateManagerError(","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/fsm/state_manager.py#L172-L208","documentation":"get_current_state_value wraps any exception from the state model's get_current_state_value query (or surrounding cache/DB work) in a StateManagerError with the original message, logging the traceback with entity and org context. This is the generic failure path for reading current state after the registry check passes — typically a database error, cache backend failure, or a bug in the state model's query method.","triggerScenarios":"Calling get_current_state_value (or transition_state/warm_cache which call it) while the DB query in state_model.get_current_state_value raises: DatabaseError (connection lost, locked tables, missing table/migration), OperationalError, or any exception raised inside the state model's custom method. The cache-miss DB path is where it surfaces.","commonSituations":"Database connectivity loss or failover mid-request; pending migrations leaving the state table absent; Redis/cache misconfiguration (e.g., REDIS_CACHE_ALIAS pointing at an unavailable backend) combined with DB errors; custom LSE state model overrides that raise on unexpected data.","solutions":["Check the server logs — the original exception is logged with exc_info, entity_id, and organization_id; fix the root cause named there (usually DB or cache).","Verify the state table exists and migrations are applied (python label_studio/manage.py migrate).","Test the cache backend configured for FSM (REDIS_CACHE_ALIAS / default cache) is reachable; restart after fixing connectivity.","Retry the operation once connectivity is restored; the error is a wrapped transient failure in many cases."],"exampleFix":"// before\nstate = StateManager.get_current_state_value(task)  # StateManagerError: Error getting current state: connection refused\n\n// after\nfrom fsm.state_manager import StateManagerError\ntry:\n    state = StateManager.get_current_state_value(task)\nexcept StateManagerError:\n    logger.exception('current-state lookup failed for task %s', task.pk)\n    state = None  # fall back / alert","handlingStrategy":"try-catch","validationCode":"from django.db import connection\n\nconnection.ensure_connection()  # fail fast before state lookup if DB is down","typeGuard":"def can_read_current_state(entity) -> bool:\n    from fsm.registry import get_state_model_for_entity\n    from django.db import connection\n    return get_state_model_for_entity(entity) is not None and connection.is_usable()","tryCatchPattern":"from fsm.state_manager import StateManagerError\ntry:\n    state = StateManager.get_current_state_value(entity)\nexcept StateManagerError as e:\n    logger.exception('current-state read failed for %s:%s', entity._meta.label_lower, entity.pk)\n    state = None  # degrade gracefully or retry with backoff","preventionTips":["Monitor DB and FSM cache (Redis) health; the error is usually a wrapped infra failure","Apply migrations promptly so state tables exist","Always read the chained root cause in logs before changing application code"],"tags":["database","state-manager","fsm","wrapped-error"],"backgroundTag":"database-query-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}