Coverage for src/lexigram/admin/actions/standard/utils.py: 100%
13 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
1"""Shared helpers for the standard admin actions."""
3from __future__ import annotations
5from typing import Any
7from lexigram.admin.actions.types import ActionContext
10def _extract_id(record: Any) -> Any | None:
11 """Extract the ``id`` field from a record dict or object.
13 Args:
14 record: A record dict or object.
16 Returns:
17 The record id, or ``None`` when absent.
18 """
19 if isinstance(record, dict):
20 return record.get("id")
21 return getattr(record, "id", None)
24def _resolve_data_source(ctx: ActionContext, injected: Any | None = None) -> Any | None:
25 """Resolve the data source for an action execution.
27 Args:
28 ctx: Action execution context.
29 injected: Constructor-injected data source, if any.
31 Returns:
32 The resolved data source, or ``None``.
33 """
34 if injected is not None:
35 return injected
36 if ctx.data_source is not None:
37 return ctx.data_source
38 return ctx.metadata.get("data_source")