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
42 changes: 39 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ there is described in full here. This list is where to start.
- **Deprecated: `tsOnly` in `meta types --format json`.** It is still emitted through 1.3.x,
derived from the new `implementedIn`, and is removed in 1.4. Read `implementedIn` instead.
- **A template that names a variable not on its payload now raises at render time** instead of
rendering the variable as empty. Regenerate, and fix the name the error reports.
rendering the variable as empty. Regenerate, and fix the name the error reports. The generated
render helpers change on regenerate: they pass the payload's field tree to the renderer (in
Python, a `verify=[PayloadField(...)]` argument and one new import), which is what makes the
check possible. An inline `render()` call that is not given the field tree is unchanged and
still renders an unknown variable as empty.
- **C#, EF Core migrations.** The first `dotnet ef migrations add` after upgrading scaffolds the
indexes, comments and CHECK constraints the context now declares. A Postgres context gets
generated design-time services that scaffold a changed `@sequenceStart` safely; in EF's default
Expand Down Expand Up @@ -166,7 +170,9 @@ there is described in full here. This list is where to start.
- **Every join a generated view or report makes is `LEFT OUTER`.** A row whose reference is null,
or whose related row is missing, now appears with nulls in the joined columns instead of
vanishing. Expect the regenerated view bodies to differ in `meta migrate`: one view replacement
per view that joined through a required reference.
per view that joined through a required reference. To keep the old row-dropping behaviour for a
view, declare `@filter: { "<hop>.id": { isNull: false } }` on the projection (no new
vocabulary); the filter lowers to a `WHERE` that removes the rows the outer join added.
- **TypeScript and C#: a projection that extends another keeps its super's identity anchor.** Over a
table-per-hierarchy root, a projection whose own fields bind a subtype's column used to return
only that subtype's rows; its view now returns **every** row of the shared table, the subtype
Expand Down Expand Up @@ -358,7 +364,12 @@ there is described in full here. This list is where to start.
four-space indent is refused with `ERR_WRITER_LEADING_WHITESPACE`, naming the subclass (in
1.3.0 release candidates it wrote a module that did not compile). Drop the indent.
`_emit_cross_field_rules` returns a step that writes the method onto the writer (or `None`)
instead of lines. `metaobjects gen` and every `metaobjects verify` mode that includes codegen
instead of lines. A member of several lines (a method) cannot be returned from
`_emit_field_lines` at all, because every returned piece is one unindented line of text, and
stripping its indentation is refused too. Override `_write_model` and write the method through
the code writer, which indents it; `extra` is the step written after the members, so wrap it to
keep what the base class put there. `_emit_cross_field_rules` is the Create-model alternative
(the `<Name>Create` class only). `metaobjects gen` and every `metaobjects verify` mode that includes codegen
(`--codegen`, and a bare `verify`) also refuse any generated `.py` file that does not compile,
naming the file and the generator; `verify --templates` alone checks prompt templates only and
does not compile generated code:
Expand All @@ -373,6 +384,31 @@ there is described in full here. This list is where to start.
lines, uses = super()._emit_field_lines(entity, imports, object_index, config)
return ['model_config = ConfigDict(extra="forbid")', *lines], uses
```

A multi-line member, such as a `model_validator` with a nested `if`/`raise`:

```python
# 1.3: override _write_model; the writer indents each line it is given
def _write_model(self, w, header, doc, members, extra):
if header.startswith("class Booking("): # the entity model, not Create or Patch
prior = extra

def check_dates(w):
if prior is not None:
prior(w)
w.use("model_validator", "pydantic")
w.blank()
w.text('''
@model_validator(mode="after")
def _check_dates(self):
if self.ends_at < self.starts_at:
raise ValueError("ends_at before starts_at")
return self
''')

extra = check_dates
super()._write_model(w, header, doc, members, extra)
```
- **Python, by hand for owned subclasses: the router and extractor hooks take the writer.**
`RouterGenerator._emit_repository_protocol`, `_emit_reverse_finders`, `_emit_route_handler`,
`_emit_m2m_route`, `_emit_tph_m2m_route`, `_emit_tph_list_body`,
Expand Down
1 change: 1 addition & 0 deletions docs/features/prerelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ top of it. Treat a failure as a build break.
### In a consumer: `tools/prerelease/detect-prerelease-pins.sh`

`link` installs it into the consumer at `tools/prerelease/detect-prerelease-pins.sh`.
A copy the consumer already tracks at that path is left as it is, so `unlink` has nothing of it to revert.
**Commit it and run it in CI** (and from a pre-commit hook). It flags:

1. the pre-release registry's host — read from `MO_REGISTRY_BASE`, never a committed
Expand Down
7 changes: 7 additions & 0 deletions tools/prerelease/estate-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ dirtymap | sort > "$WORK/base.txt"
changes "$WORK/linked.txt" "$WORK/base.txt" > "$WORK/installed.txt"
row "files changed by install" "$(wc -l < "$WORK/installed.txt")" 0
( cd "$PROJECT" && bash -c "$VERSIONS_CMD" ) > "$WORK/versions.txt" 2>&1
# `pip show` / `uv pip show` print `Name: metaobjects` and `Version: x` on separate lines: join a
# Version line onto the Name line before it, so the checks below see one line per package.
awk '/^Name:/ { if (held != "") print held; held = $0; next }
/^Version:/ && held != "" { print held " " $0; held = ""; next }
{ if (held != "") { print held; held = "" } print }
END { if (held != "") print held }' "$WORK/versions.txt" > "$WORK/versions.joined" \
&& mv "$WORK/versions.joined" "$WORK/versions.txt"
# Every line that names a MetaObjects package must carry exactly the candidate (not rc.10 for rc.1,
# not a package left on the release), and at least one must.
VCOUNT="$(grep -ci 'metaobjects' "$WORK/versions.txt")"
Expand Down
6 changes: 6 additions & 0 deletions tools/prerelease/prerelease-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,12 @@ link_mvn() {
install_detector() {
local dst="$PROJECT/tools/prerelease/detect-prerelease-pins.sh"
[ "$HERE/detect-prerelease-pins.sh" -ef "$dst" ] && return 0
# A copy the project already tracks is its own: overwriting it would leave a modification
# that `unlink` (which removes only what `link` added) never reverts.
if git -C "$PROJECT" ls-files --error-unmatch -- tools/prerelease/detect-prerelease-pins.sh >/dev/null 2>&1; then
say "tools/prerelease/detect-prerelease-pins.sh is tracked here — left as it is"
return 0
fi
mkdir -p "$(dirname "$dst")"
cp "$HERE/detect-prerelease-pins.sh" "$dst"; chmod +x "$dst"
say "installed tools/prerelease/detect-prerelease-pins.sh — COMMIT IT and run it in CI"
Expand Down
9 changes: 9 additions & 0 deletions tools/prerelease/test-estate-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ e11() { local d before; d="$(fresh "$IDEMPOTENT")"
--gen-cmd 'sh gen.sh' >/dev/null 2>&1; [ $? = 1 ] || return 1
[ -z "$(git -C "$d" status --porcelain --untracked-files=all)" ]; }

e21() { local d out; d="$(fresh "$IDEMPOTENT")"
out="$(run "$d" 1.3.0-rc.6 python $VERS 'printf "Name: metaobjects\nVersion: 1.3.0rc6\nLocation: /x\n"')"; rc=$?
[ $rc = 0 ] && grep -q 'installed version is 1.3.0rc6 | passed' <<<"$out"; }
e22() { local d out; d="$(fresh "$IDEMPOTENT")"
out="$(run "$d" 1.3.0-rc.6 python $VERS 'printf "Name: metaobjects\nVersion: 1.2.3\n"')"; rc=$?
[ $rc = 1 ] && grep -q 'installed version is 1.3.0rc6 | \*\*FAILED' <<<"$out"; }

t "E1 a clean run passes and lists what the first gen changed" e1
t "E2 a gen that writes on every run fails the zero-write check" e2
t "E3 a gen that rewrites identical bytes fails the zero-write check" e3
Expand All @@ -109,6 +116,8 @@ t "E8 a stale package or rc.10 fails the read-back check" e8
t "E9 the estate is put back on its starting commit" e9
t "E12 --no-link still restores the estate" e12
t "E13 --keep-linked leaves the regenerated tree in place" e13
t "E21 pip-show output (version on its own line) passes the read-back" e21
t "E22 pip-show output on another version fails the read-back" e22
t "E10 a report path inside the estate is refused" e10
t "E11 a link that fails partway still restores the estate" e11
e14() { local d bin log; d="$(fresh "$IDEMPOTENT")"; bin="$(mktemp -d "$ROOT/bin.XXXXXX")"; log="$bin/mvn.log"
Expand Down
14 changes: 14 additions & 0 deletions tools/prerelease/test-prerelease-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -552,5 +552,19 @@ MO_REGISTRY_BASE="https://registry.widget.internal:3000" bash "$DETECT" "$lockpr
check "detector output carries no registry host" '! grep -q "widget.internal" "$WORK/lock-out" && ! grep -q "token=abc" "$WORK/lock-out"'
check "detector output still names the package and version" 'grep -q "metadata-1.1.0-rc.9.tgz" "$WORK/lock-out" && grep -q "package-lock.json" "$WORK/lock-out"'

# a project that tracks its own copy of the detector: link leaves it alone, so unlink leaves it clean.
detp="$WORK/detp"
mkdir -p "$detp/tools/prerelease"
git -C "$detp" init -q; git -C "$detp" config user.email t@t; git -C "$detp" config user.name t
printf '{"dependencies":{"@metaobjectsdev/metadata":"1.2.0"}}\n' > "$detp/package.json"
printf '#!/usr/bin/env bash\n# the project'"'"'s own older copy\nexit 0\n' > "$detp/tools/prerelease/detect-prerelease-pins.sh"
chmod +x "$detp/tools/prerelease/detect-prerelease-pins.sh"
git -C "$detp" add -A && git -C "$detp" commit -q -m init
link "$detp" || fail "link failed on the project with a tracked detector: $(tail -5 "$WORK/out")"
check "link leaves a tracked detector copy unmodified" 'git -C "$detp" diff --quiet -- tools/prerelease/detect-prerelease-pins.sh'
unlink_noto "$detp"
check "unlink leaves the tracked detector copy unmodified" 'git -C "$detp" diff --quiet -- tools/prerelease/detect-prerelease-pins.sh'
check "unlink leaves the project clean" '[ -z "$(git -C "$detp" status --porcelain --untracked-files=all)" ]'

[ "$fails" -eq 0 ] || { echo "$fails failure(s)" >&2; exit 1; }
echo "all prerelease-link tests passed"
Loading