HumanSignal/label-studio · error · StateManagerError

Error getting current state: {e}

Error message

Error getting current state: {e}

What it means

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.

Source

Thrown at label_studio/fsm/state_manager.py:190

                        'organization_id': CurrentContext.get_organization_id(),
                    },
                )

            return current_state

        except Exception as e:
            logger.error(
                'FSM: Error getting current state',
                extra={
                    'event': 'fsm.get_state_error',
                    'entity_type': entity._meta.label_lower,
                    'entity_id': entity.pk,
                    'organization_id': CurrentContext.get_organization_id(),
                    'error': str(e),
                },
                exc_info=True,
            )
            raise StateManagerError(f'Error getting current state: {e}') from e

    @classmethod
    def get_current_state_object(cls, entity: Model) -> BaseState:
        """
        Get current state object with full audit information.

        Args:
            entity: The entity to get current state object for

        Returns:
            Latest BaseState instance

        Raises:
            StateManagerError: If no state model found
        """
        state_model = get_state_model_for_entity(entity)
        if not state_model:
            raise StateManagerError(

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. 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).
  2. Verify the state table exists and migrations are applied (python label_studio/manage.py migrate).
  3. Test the cache backend configured for FSM (REDIS_CACHE_ALIAS / default cache) is reachable; restart after fixing connectivity.
  4. Retry the operation once connectivity is restored; the error is a wrapped transient failure in many cases.

Example fix

// before
state = StateManager.get_current_state_value(task)  # StateManagerError: Error getting current state: connection refused

// after
from fsm.state_manager import StateManagerError
try:
    state = StateManager.get_current_state_value(task)
except StateManagerError:
    logger.exception('current-state lookup failed for task %s', task.pk)
    state = None  # fall back / alert
Defensive patterns

Strategy: try-catch

Validate before calling

from django.db import connection

connection.ensure_connection()  # fail fast before state lookup if DB is down

Type guard

def can_read_current_state(entity) -> bool:
    from fsm.registry import get_state_model_for_entity
    from django.db import connection
    return get_state_model_for_entity(entity) is not None and connection.is_usable()

Try / catch

from fsm.state_manager import StateManagerError
try:
    state = StateManager.get_current_state_value(entity)
except StateManagerError as e:
    logger.exception('current-state read failed for %s:%s', entity._meta.label_lower, entity.pk)
    state = None  # degrade gracefully or retry with backoff

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/8eb088838b6c5959. Report an issue: GitHub.