Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ approval emits a warning; it is not automatic rejection. Marking for deletion
stages a change—the audited Save performs it. Atomicity is provider/route scoped,
not a distributed transaction across unrelated databases.

Automatic Context values (clock, IP, actor) supplement an independently changed
entity; a different Context cannot turn an unchanged save into an update.
The [Context Fix example](examples/context-derived/) demonstrates staged values,
field-level errors, graph rollback and retry using generated Q/E and audited save.

## Automatic logs without handwritten logging code

**Debuggability and operability are core design goals.** The Q and Save
Expand Down
32 changes: 32 additions & 0 deletions examples/context-derived/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Context Fix over generated Q/E and audited SQLite saves

Run from the runtime checkout:

```sh
PYTHONPATH=src python examples/context-derived/verify-local.py
```

The verifier binds the actual repository runtime and immutable generated library,
checks their origins/hashes, and runs twice against the same isolated SQLite
database. `TEAQL_CONTEXT_FIX_EVIDENCE_DIR` chooses a new evidence directory;
otherwise a compact temporary evidence directory is retained. No build tree or
virtual environment is created by the verifier. Logs, receipts and the synthetic
database are retained; generated sources are never patched.

The example proves unchanged Context A rows are not refreshed under Context B;
real business changes enable update-scoped clock/IP/actor values while preserving
create-only values. Provider/validation failures carry ObjectLocation; caller
intent survives, earlier sibling Fix rolls back after a later failure, and retry
changes just the independently dirty child. The prepared path also checks a
Context function executes once per entity/operation, not once per planning pass.

IP/actor declarations are an application metadata/Checker SPI customization over
ordinary strings. The synchronous `context_fix_resolver` receives ContextFixInput;
prepare asynchronous external results before save. Raw provider errors and
causes are not part of the public Check failure.

Regenerate this fixture using the generator's `PythonContextFixGenerationTest`
with `-Dteaql.python.context.fixture.output=<absolute fixture directory>`.
The `teaql/model-provenance.json` directory is metadata only, not an embedded
runtime; the canonical verifier checks its manifest hash and rejects Python
source, bytecode, symlinks, unowned metadata or unexpected files there.
143 changes: 143 additions & 0 deletions examples/context-derived/fixture/E.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
from teaql.runtime import ExpressionPath, JsonFieldNamingProfile, TeaQLNotLoadedError


class ValueExpression:
def __init__(self, value=None, error=None):
self._value = value
self._error = error

def eval(self):
if self._error is not None:
raise self._error.terminal("eval()")
return self._value

def or_if_null(self, fallback):
if self._error is not None:
raise self._error.terminal("or_if_null(<fallback>)")
return fallback if self._value is None else self._value


class EntityExpression:
def __init__(self, value, root=None, path=None, error=None):
self._value = value
self._root = root
self._path = path if path is not None else ExpressionPath("E.entity(<root>)")
self._error = error

def eval(self):
if self._error is not None:
raise self._error.terminal("eval()")
return self._value

def _scalar(self, field, canonical, method, relation_id=False):
path = self._path.member(canonical, method)
if self._error is not None:
return ValueExpression(error=self._error.with_path(path))
if self._value is None:
return ValueExpression(None)
if field not in getattr(self._value, "_loaded_fields", set()):
return ValueExpression(error=TeaQLNotLoadedError(path.mark_missing(), canonical))
value = getattr(self._value, field)
if relation_id and value is not None and not isinstance(value, (int, str)):
value = getattr(value, "id", None)
return ValueExpression(value)

def _relation(self, field, canonical, method, expression_type):
path = self._path.member(canonical, method)
if self._error is not None:
return expression_type(None, self._root, path, self._error.with_path(path))
if self._value is None:
return expression_type(None, self._root, path)
if field not in getattr(self._value, "_loaded_fields", set()):
return expression_type(None, self._root, path, TeaQLNotLoadedError(path.mark_missing(), canonical))
value = getattr(self._value, field)
if value is not None and isinstance(value, (int, str)):
return expression_type(None, self._root, path, TeaQLNotLoadedError(path.mark_missing(), canonical))
return expression_type(value, self._root, path)

def _list(self, field, canonical, method, item_expression):
path = self._path.member(canonical, method)
if self._error is not None:
return ListExpression([], self._root, path, item_expression, self._error.with_path(path))
if self._value is None:
return ListExpression([], self._root, path, item_expression)
if field not in getattr(self._value, "_loaded_fields", set()):
return ListExpression([], self._root, path, item_expression, TeaQLNotLoadedError(path.mark_missing(), canonical))
return ListExpression(getattr(self._value, "_" + field), self._root, path, item_expression)


class ListExpression:
def __init__(self, values, root, path, item_expression, error=None):
self._values = values
self._root = root
self._path = path
self._item_expression = item_expression
self._error = error

def size(self):
return (ValueExpression(error=self._error.with_path(self._path.operation("size()")))
if self._error else ValueExpression(len(self._values)))

def first(self):
return self._item(0, first=True)

def get(self, index):
return self._item(index)

def _item(self, index, first=False):
path = self._path.index(index, first)
if self._error is not None:
return self._item_expression(None, self._root, path, self._error.with_path(path))
value = self._values[index] if 0 <= index < len(self._values) else None
return self._item_expression(value, self._root, path)


class CatalogExpression(EntityExpression):
def id(self):
return self._scalar("id", "id", "id")
def name(self):
return self._scalar("name", "name", "name")
def version(self):
return self._scalar("version", "version", "version")
def entry_list(self):
return self._list("entry_list", "entry_list", "entry_list", EntryExpression)
pass

class EntryExpression(EntityExpression):
def id(self):
return self._scalar("id", "id", "id")
def name(self):
return self._scalar("name", "name", "name")
def born_at(self):
return self._scalar("bornAt", "born_at", "born_at")
def touched_at(self):
return self._scalar("touchedAt", "touched_at", "touched_at")
def source_ip(self):
return self._scalar("sourceIp", "source_ip", "source_ip")
def last_ip(self):
return self._scalar("lastIp", "last_ip", "last_ip")
def opened_by(self):
return self._scalar("openedBy", "opened_by", "opened_by")
def changed_by(self):
return self._scalar("changedBy", "changed_by", "changed_by")
def guarded_token(self):
return self._scalar("guardedToken", "guarded_token", "guarded_token")
def version(self):
return self._scalar("version", "version", "version")
def catalog_id(self):
return self._scalar("catalog", "catalog", "catalog_id", relation_id=True)

def catalog(self):
return self._relation("catalog", "catalog", "catalog", CatalogExpression)
pass

class E:
@staticmethod
def catalog(value):
return CatalogExpression(value, path=ExpressionPath(
"E.catalog(<root>)", JsonFieldNamingProfile.parse("camelCase")))
@staticmethod
def entry(value):
return EntryExpression(value, path=ExpressionPath(
"E.entry(<root>)", JsonFieldNamingProfile.parse("camelCase")))
pass
22 changes: 22 additions & 0 deletions examples/context-derived/fixture/Q.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by teaql-code-gen
from requests.catalog_request import CatalogRequest
from requests.entry_request import EntryRequest

class Q:
@staticmethod
def catalogs() -> CatalogRequest:
return CatalogRequest(minimal=False)

@staticmethod
def catalogs_minimal() -> CatalogRequest:
return CatalogRequest(minimal=True)

@staticmethod
def entries() -> EntryRequest:
return EntryRequest(minimal=False)

@staticmethod
def entries_minimal() -> EntryRequest:
return EntryRequest(minimal=True)


15 changes: 15 additions & 0 deletions examples/context-derived/fixture/generated-files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"E.py" : "e097b358bc8f2a781ce6792a05a3e0a5f8e96cca4dd94989d33fc33dd650ff94",
"Q.py" : "d203912175a89813932f55d2b5f16549499e51df93f4816d4c080a275f45ab1a",
"generated_search_models.py" : "1851c069a0f34b9aad88725ceda3fa706b42eff03df18dc2f5dd212349868af0",
"models/__init__.py" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"models/catalog.py" : "8f27a6151ce07d5617784327fe70f5c3dbc0f5b950602b1dd964fcfe54bb2604",
"models/entry.py" : "4125cfd7b222b5280c009cc2690ee3602f5bf67e017f37e550da09748d1f5961",
"pyproject.toml" : "c1a2a5d57b04de9e7468a5e58eb60f3a03917d18aff0431fafe6d17697862ccf",
"requests/__init__.py" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"requests/catalog_request.py" : "b66a29e2194de774644cc82e3b4aaa19d10c77869ef2c255e07a44d0e82bad6e",
"requests/entry_request.py" : "36c18f2d681bead8642742ecec032eef124edacb744475fe991b08da579aa31d",
"runtime_module.py" : "1c6312b3e9f0ebd2dd4bfa963dd53b1a50ece033dc6d71ac9bb29e5acb095f15",
"teaql-i18n.json" : "872f2be4fb4df7d76c732d627ae016b07cb39591ef833169277c67db4ec726e8",
"teaql/model-provenance.json" : "2fce8608af8dc31b56c3e98779917206e1b076b81dcc2e17bd2fe0db4d6d1a82"
}
65 changes: 65 additions & 0 deletions examples/context-derived/fixture/generated_search_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from types import MappingProxyType

# Generated trusted field/type metadata. Runtime owns parsing, binding and warnings.
GENERATED_SEARCH_MODELS = MappingProxyType({
"Catalog": MappingProxyType({
"fields": MappingProxyType({
"id": "integer",
"name": "string",
"version": "integer",
}),
"query_fields": MappingProxyType({
"id": "id",
"name": "name",
"version": "version",
}),
"relations": MappingProxyType({
"entryList": "Entry",
}),
}),
"Entry": MappingProxyType({
"fields": MappingProxyType({
"id": "integer",
"catalog": "integer",
"name": "string",
"born_at": "timestamp",
"bornAt": "timestamp",
"touched_at": "timestamp",
"touchedAt": "timestamp",
"source_ip": "string",
"sourceIp": "string",
"last_ip": "string",
"lastIp": "string",
"opened_by": "string",
"openedBy": "string",
"changed_by": "string",
"changedBy": "string",
"guarded_token": "string",
"guardedToken": "string",
"version": "integer",
}),
"query_fields": MappingProxyType({
"id": "id",
"catalog": "catalog",
"name": "name",
"born_at": "born_at",
"bornAt": "born_at",
"touched_at": "touched_at",
"touchedAt": "touched_at",
"source_ip": "source_ip",
"sourceIp": "source_ip",
"last_ip": "last_ip",
"lastIp": "last_ip",
"opened_by": "opened_by",
"openedBy": "opened_by",
"changed_by": "changed_by",
"changedBy": "changed_by",
"guarded_token": "guarded_token",
"guardedToken": "guarded_token",
"version": "version",
}),
"relations": MappingProxyType({
"catalog": "Catalog",
}),
}),
})
5 changes: 5 additions & 0 deletions examples/context-derived/fixture/model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<root name="context-fix-service" org="example" data_service="sqlite">
<catalog name="Catalog"/>
<entry catalog="catalog()" name="Entry" born_at="createTime()" touched_at="updateTime()"
source_ip="string()" last_ip="string()" opened_by="string()" changed_by="string()" guarded_token="uniStr()"/>
</root>
Empty file.
Loading
Loading