Inject state dicts by name (prev/state), rename MigrationResult to MigrationReport.
State dict injection now works by parameter name (prev/state, annotation not checked) with DictPrev/DictState tags taking precedence; DictPre/DictPost remain as aliases. MigrationResult is renamed to MigrationReport with fields original/version/applied; the old type alias and a deprecated .migrations property remain. Old symbols stay covered by the original tests; new-style tests import from the kanta root. Includes some unrelated ruff formatting.
This commit is contained in:
+3
-5
@@ -6,9 +6,7 @@ from pathlib import Path
|
||||
|
||||
import msgspec
|
||||
|
||||
from kanta import Kanta
|
||||
from kanta.callbacks import DictPre
|
||||
from kanta.logging import configure_logging
|
||||
from kanta import Kanta, configure_logging
|
||||
|
||||
|
||||
filename = Path(__file__).with_name("demo.kantadb")
|
||||
@@ -47,11 +45,11 @@ kanta_v1 = Kanta(filename, Data(), migrations=sys.modules[__name__])
|
||||
|
||||
|
||||
@kanta_v1.logfmt
|
||||
def resolve_user(value: str, path: str, previous: DictPre) -> str | None:
|
||||
def resolve_user(value: str, path: str, state: dict) -> str | None:
|
||||
"""Resolve user ids to names from the database state itself."""
|
||||
if path != "$user" and not path.startswith("users."):
|
||||
return None
|
||||
return previous.get("users", {}).get(value, {}).get("name")
|
||||
return state.get("users", {}).get(value, {}).get("name")
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
Reference in New Issue
Block a user