> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# states

# `prefect.server.schemas.states`

State schemas.

## Functions

### `Scheduled` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L315](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L315)</sup>

```python theme={null}
Scheduled(scheduled_time: Optional[DateTime] = None, cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Scheduled` states.

**Returns:**

* a Scheduled state

### `Completed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L337](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L337)</sup>

```python theme={null}
Completed(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Completed` states.

**Returns:**

* a Completed state

### `Running` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L346](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L346)</sup>

```python theme={null}
Running(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Running` states.

**Returns:**

* a Running state

### `Failed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L355](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L355)</sup>

```python theme={null}
Failed(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Failed` states.

**Returns:**

* a Failed state

### `Crashed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L364](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L364)</sup>

```python theme={null}
Crashed(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Crashed` states.

**Returns:**

* a Crashed state

### `Cancelling` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L373](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L373)</sup>

```python theme={null}
Cancelling(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Cancelling` states.

**Returns:**

* a Cancelling state

### `Cancelled` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L382](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L382)</sup>

```python theme={null}
Cancelled(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Cancelled` states.

**Returns:**

* a Cancelled state

### `Pending` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L391](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L391)</sup>

```python theme={null}
Pending(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Pending` states.

**Returns:**

* a Pending state

### `Paused` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L400](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L400)</sup>

```python theme={null}
Paused(cls: type[_State] = State, timeout_seconds: Optional[int] = None, pause_expiration_time: Optional[DateTime] = None, reschedule: bool = False, pause_key: Optional[str] = None, **kwargs: Any) -> _State
```

Convenience function for creating `Paused` states.

**Returns:**

* a Paused state

### `Suspended` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L434](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L434)</sup>

```python theme={null}
Suspended(cls: type[_State] = State, timeout_seconds: Optional[int] = None, pause_expiration_time: Optional[DateTime] = None, pause_key: Optional[str] = None, **kwargs: Any) -> _State
```

Convenience function for creating `Suspended` states.

**Returns:**

* a Suspended state

### `AwaitingRetry` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L457](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L457)</sup>

```python theme={null}
AwaitingRetry(cls: type[_State] = State, scheduled_time: Optional[DateTime] = None, **kwargs: Any) -> _State
```

Convenience function for creating `AwaitingRetry` states.

**Returns:**

* an AwaitingRetry state

### `AwaitingConcurrencySlot` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L472](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L472)</sup>

```python theme={null}
AwaitingConcurrencySlot(cls: type[_State] = State, scheduled_time: Optional[DateTime] = None, **kwargs: Any) -> _State
```

Convenience function for creating `AwaitingConcurrencySlot` states.

**Returns:**

* an AwaitingConcurrencySlot state

### `Submitting` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L490](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L490)</sup>

```python theme={null}
Submitting(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Submitting` states.

**Returns:**

* a Submitting state

### `InfrastructurePending` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L499](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L499)</sup>

```python theme={null}
InfrastructurePending(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `InfrastructurePending` states.

**Returns:**

* an InfrastructurePending state

### `Retrying` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L508](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L508)</sup>

```python theme={null}
Retrying(cls: type[_State] = State, **kwargs: Any) -> _State
```

Convenience function for creating `Retrying` states.

**Returns:**

* a Retrying state

### `Late` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L517](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L517)</sup>

```python theme={null}
Late(cls: type[_State] = State, scheduled_time: Optional[DateTime] = None, **kwargs: Any) -> _State
```

Convenience function for creating `Late` states.

**Returns:**

* a Late state

## Classes

### `StateType` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L40](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L40)</sup>

Enumeration of state types.

**Methods:**

#### `auto` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70)</sup>

```python theme={null}
auto() -> str
```

Exposes `enum.auto()` to avoid requiring a second import to use `AutoEnum`

### `CountByState` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L54](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L54)</sup>

**Methods:**

#### `check_key` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L67](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L67)</sup>

```python theme={null}
check_key(cls, value: Optional[Any], info: ValidationInfo) -> Optional[Any]
```

#### `model_validate_list` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/\_internal/schemas/bases.py#L56](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/_internal/schemas/bases.py#L56)</sup>

```python theme={null}
model_validate_list(cls, obj: Any) -> list[Self]
```

#### `reset_fields` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/\_internal/schemas/bases.py#L85](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/_internal/schemas/bases.py#L85)</sup>

```python theme={null}
reset_fields(self: Self) -> Self
```

Reset the fields of the model that are in the `_reset_fields` set.

**Returns:**

* A new instance of the model with the reset fields.

### `StateDetails` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L81](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L81)</sup>

**Methods:**

#### `model_validate_list` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/\_internal/schemas/bases.py#L56](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/_internal/schemas/bases.py#L56)</sup>

```python theme={null}
model_validate_list(cls, obj: Any) -> list[Self]
```

#### `reset_fields` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/\_internal/schemas/bases.py#L85](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/_internal/schemas/bases.py#L85)</sup>

```python theme={null}
reset_fields(self: Self) -> Self
```

Reset the fields of the model that are in the `_reset_fields` set.

**Returns:**

* A new instance of the model with the reset fields.

### `StateBaseModel` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L106](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L106)</sup>

**Methods:**

#### `orm_dict` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L107](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L107)</sup>

```python theme={null}
orm_dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]
```

This method is used as a convenience method for constructing fixtues by first
building a `State` schema object and converting it into an ORM-compatible
format. Because the `data` field is not writable on ORM states, this method
omits the `data` field entirely for the purposes of constructing an ORM model.
If state data is required, an artifact must be created separately.

### `State` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L122](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L122)</sup>

Represents the state of a run.

**Methods:**

#### `default_name_from_type` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L167](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L167)</sup>

```python theme={null}
default_name_from_type(self) -> Self
```

If a name is not provided, use the type

#### `default_scheduled_start_time` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L177](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L177)</sup>

```python theme={null}
default_scheduled_start_time(self) -> Self
```

#### `fresh_copy` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L216](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L216)</sup>

```python theme={null}
fresh_copy(self, **kwargs: Any) -> Self
```

Return a fresh copy of the state with a new ID.

#### `from_orm_without_result` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L141](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L141)</sup>

```python theme={null}
from_orm_without_result(cls, orm_state: Union['ORMFlowRunState', 'ORMTaskRunState'], with_data: Optional[Any] = None) -> Self
```

During orchestration, ORM states can be instantiated prior to inserting results
into the artifact table and the `data` field will not be eagerly loaded. In
these cases, sqlalchemy will attempt to lazily load the the relationship, which
will fail when called within a synchronous pydantic method.

This method will construct a `State` object from an ORM model without a loaded
artifact and attach data passed using the `with_data` argument to the `data`
field.

#### `is_cancelled` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L204](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L204)</sup>

```python theme={null}
is_cancelled(self) -> bool
```

#### `is_cancelling` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L207](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L207)</sup>

```python theme={null}
is_cancelling(self) -> bool
```

#### `is_completed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L195](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L195)</sup>

```python theme={null}
is_completed(self) -> bool
```

#### `is_crashed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L201](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L201)</sup>

```python theme={null}
is_crashed(self) -> bool
```

#### `is_failed` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L198](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L198)</sup>

```python theme={null}
is_failed(self) -> bool
```

#### `is_final` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L210](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L210)</sup>

```python theme={null}
is_final(self) -> bool
```

#### `is_paused` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L213](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L213)</sup>

```python theme={null}
is_paused(self) -> bool
```

#### `is_pending` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L189](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L189)</sup>

```python theme={null}
is_pending(self) -> bool
```

#### `is_running` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L192](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L192)</sup>

```python theme={null}
is_running(self) -> bool
```

#### `is_scheduled` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L186](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L186)</sup>

```python theme={null}
is_scheduled(self) -> bool
```

#### `orm_dict` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L107](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L107)</sup>

```python theme={null}
orm_dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]
```

This method is used as a convenience method for constructing fixtues by first
building a `State` schema object and converting it into an ORM-compatible
format. Because the `data` field is not writable on ORM states, this method
omits the `data` field entirely for the purposes of constructing an ORM model.
If state data is required, an artifact must be created separately.

#### `result` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L232](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L232)</sup>

```python theme={null}
result(self, raise_on_failure: Literal[True] = ...) -> Any
```

#### `result` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L235](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L235)</sup>

```python theme={null}
result(self, raise_on_failure: Literal[False] = False) -> Union[Any, Exception]
```

#### `result` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L240](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L240)</sup>

```python theme={null}
result(self, raise_on_failure: bool = ...) -> Union[Any, Exception]
```

#### `result` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L242](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L242)</sup>

```python theme={null}
result(self, raise_on_failure: bool = True) -> Union[Any, Exception]
```

#### `to_state_create` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L259](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/schemas/states.py#L259)</sup>

```python theme={null}
to_state_create(self) -> 'StateCreate'
```
