Repository navigation
feat: a block of Python where a command would go - #42
Closed
AlexeyShalaev wants to merge 1 commit into
Closed
AlexeyShalaev wants to merge 1 commit into
AlexeyShalaev wants to merge 1 commit into
Conversation
The authentik model, for the Python-adjacent audience: a phase in a document takes a block of Python -- inline as python, or from a file as python_file relative to the document -- evaluated with event and log in scope, raising to refuse. PythonHooks is the same from code, in both mirrors, on the shared runner in pg_partsmith.python_hooks. Every block is compiled when the document is read, and a file-backed one by validate: a SyntaxError is a validation error with a line number in it, not something a CronJob finds at 03:00 after some of the run's DDL has committed. Tracebacks name the phase, or the file, rather than <string>. It is behind the same --allow-hooks as a command, because a Python hook is a hook and the trust argument is the same one. No sandbox is claimed: exec with a filtered __builtins__ is not a security boundary, and the docs say so rather than pretending otherwise. Isolation, if wanted, is a command hook in a container of its own. Retention predicates as Python are deliberately not in this change. They would run during plan, not apply, which is a different gate and a different promise about what plan is allowed to do.
This was referenced Sep 1, 2026
Member
Author
|
Folded into #43, one PR for the whole epic; this branch stays for history. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3a of #32, scoped to hooks — exactly what the epic describes under "Inline Python blocks (the authentik model)".
The block sees
event(the samePartitionEventa hook class is handed) andlog; nothing else is injected. Raising refuses the operation, exactly as a non-zero exit does for a command.Every one of the epic's four notes on 3a is done:
DROP(the partition stays detached and undropped).python_file, resolved relative to the document. Not a YAML tag: a plain key needs no custom loader and works in JSON too.validatemust compile every snippet without executing it — inline blocks compile the moment the document validates (aSyntaxErroris aValidationErrorwith the line in it); file-backed ones are read and compiled by every command before a connection is opened, sovalidatefails on a missing or broken file by name.plan— already structurally true, and tested.On security, the epic's own words made mechanical: code hooks are off unless enabled, and the flag is the existing
--allow-hooks— a Python hook is a hook, and the trust argument (the document already authorisesDROP; that stops holding when the document comes from a less trusted place than the DSN) is the same one word for word. The docs say there is no sandbox, and why claiming one would be worse than having none.What is deliberately not here: retention predicates as Python (
Callbackin config). They would run duringplan, which is a different gate and a different promise about whatplanis allowed to do. The compile/namespace machinery here is what they would reuse; a follow-up if wanted.9 unit tests on the runner (both mirrors), 5 on the document, 4 on the CLI, 2 against a real PostgreSQL. Stacked on #41.