Repository navigation
fix(python): routes refusal, arrays off Postgres, projection load checks - #637
Merged
Merged
Conversation
…skip - A primitive array (string, number, date, uuid, enum) persists on SQLite and MySQL as a JSON array; an int-backed enum's elements as their integers. roundtrip-int-enum-array now runs on both engines. A date/time/timestamp array is parsed element by element on write (it was refused on every engine). - The generator-selection check counts only the objects a generator writes output for: an unlimited `routes` is no longer refused over abstract or sourceless objects the limited `filter-allowlist` leaves out. - `eject --force` over a copy identical to the reference writes nothing. - The TPH foreign-discriminator scenario runs in Python's generated lane; the stale skip and KNOWN_GAPS entry are removed.
…r (W-PY-2) The model modules, the shared enums module and the duration codec banner are built on a PyWriter and ruff no longer runs over them (ADR-0063). Checked against 1,561 modules generated from the repository's fixtures: 1,146 are byte-identical and the other 415 match once both versions get the same ruff import sort and format. PyWriter.gap() before the first body line now gives two blank lines after the imports, with a new py-gap-after-imports writer-conformance case.
… by its flat key A reference whose @fields is a flattened value-object member (address.countryId) put the dotted path into the finder method names, so the generated router was not valid Python. It now uses the flat key (addressCountryId), as TypeScript's flatKeyOfPath does.
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.
What Changed
metaobjects genno longer refuses an unrestrictedroutesover abstract or sourceless objects it writes nothing for. Theentitylimit check covers the routed objects plus their model imports (extends chain, value objects, M:N targets, concrete subtypes of a routed discriminator base), so a limit that drops a real import still refuses.eject --forceleaves a copy that already matches the reference untouched and reports it asunchanged. The entity model generator now writes through the Python code writer (ADR-0063) instead of runningruffover its output, so the bytes no longer depend on whetherruffis installed. TPH subtype models pin the discriminator withLiteral, and the TPH foreign-discriminator scenario now runs in the Python generated lane (the stale skip and KNOWN_GAPS entry are removed). A reference through a flattened value-object member (address.countryId) names its reverse finder by the flat key (find_plans_by_address_country).TEXT) and MySQL (JSON) as JSON arrays, and int-backed enum arrays store their integers. Date, time and timestamp arrays are parsed element by element on write, on every engine. Theroundtrip-int-enum-arrayscenario runs on SQLite and MySQL instead of being deferred.@unionmember shape (name, subtype, array-ness,@column, enum members and value maps) and@graintargets are validated at load, plus@unionAllwithout@unionand a malformed@grainOrdinal. Each failure isERR_BAD_ATTR_VALUE. The Python ledger dropserror-projection-union-shapeanderror-projection-grain-not-object-array.Notes
docs/ports/python.mddescribe both.ruffimport-sort and format pass, not by byte equality.Validation
Risk Assessment
✅ Low: The fix round correctly adds TPH subtypes to the entity import closure, and the added test exercises the refusal path; the earlier work matches the stated intent and I found no wrong-result path.
Testing
Drove three scenarios live with the real
metaobjectsCLI from the branch venv on disposable RAM fixtures, then removed them. All three pass: unrestricted routes no longer spuriously refuse and the generated routers import; genuine refusals (abstract base and TPH subtype outside entity's selection) still refuse with no output written;eject --forceleaves identical copies untouched and still replaces differing ones. Base-tree runs reproduce the old spurious refusal, so the fix is shown. Not driven live in this turn, because the scenario cap was three: C5 enum list (needs Postgres),@union/@grainloader errors, W-PY-2 entity writer goldens, the flattened reverse-finder name, and the CHANGELOG bullets. Those rely on the baseline affected lanes that passed at 6c5d73a.python -I -c 'import gen.order_router, gen.invoice_router'ok; base tree exit 1 with spurious refus…unchanged entity -> codegen/generators/entity.py (already the reference), mtime_ns and sha256 unchanged; after a hand edit,eject --forcerestored the reference…Evidence: S1 unrestricted routes: fixed tree exit 0 and base tree spurious refusal
Evidence: S2 entity-closure refusal (abstract base, TPH subtype) on fixed and base trees
Evidence: S3 eject --force unchanged skip and differing-copy replace
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
server/python/src/metaobjects/codegen/generator_registry.py:378-model_import_closure(entity_model.py:1072) misses the TPH subtypes a routed discriminator base imports. The round-1 fix is incomplete for this case. A TPH subtype emits no router of its own (emits_instance_artifactsexcludesis_tph_subtype, shared_predicates.py:208). The base's router imports<Sub>Createand<Sub>Patchfrom each subtype's model module (router_generator.py:1631-1634).model_importsreturns only the extends base, value-object targets and M:N targets, so subtypes never enter the closure. Concrete sequence:[{name: entity, packages: ['acme::sales']}, routes], with a routed discriminator baseAuthinacme::salesand a concrete subtypeBridge(@discriminatorValue) inacme::catalog. The subtype is not routed, so it is not inwritten. It is not in the closure ofAutheither.gapis empty,genexits 0, andauth_router.pyimports aBridge.pythat was never written, so the generated package fails at import. This is the failure therequirescheck exists to prevent, and the intent says a routed object whose model would import an unwritten module must still refuse. Fix: inmodel_imports(or in theentitylambda incovers), addtph_plan_for(entity, index).subtypesentities for a discriminator base. The closure then also covers the subtypes' own value objects and M:N targets. Add a test besidetest_the_many_to_many_target_a_routed_object_imports_is_needed_from_entity.CHANGELOG.md:201- The CHANGELOG records most of this branch's Python items but omits two. (1)metaobjects eject --forceover a copy that already matches the reference now writes nothing and printsunchanged ...(eject.py:150-157). The C# equivalent is documented at CHANGELOG.md:41-45. (2) A reference whose@fieldsis a flattened value-object member (address.countryId) used to emit a reverse-finder name containing a dot. It is now named by the flat key,find_plans_by_address_country(router_generator.py:821). The generated method names change on upgrade for such models, which is exactly the kind of diff the changelog is meant to warn about. Add one bullet for each.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
python -I -c 'import gen.order_router, gen.invoice_router'ok; base tree exit 1 with spurious refus…unchanged entity -> codegen/generators/entity.py (already the reference), mtime_ns and sha256 unchanged; after a hand edit,eject --forcerestored the reference…scripts/ci-local.sh --affected --strict-toolchainsBuilt disposable fixture projects under $DEV_SCRATCH (RAM), removed after run: s1 (unrestricted routes, entity limited to acme::sales, abstract Base and sourceless Ledger outside selection); s2a (routed Order extends abstract acme::common::Base, entity limited); s2b (routed discriminator Auth, TPH subtype BridgeAuth in acme::catalog, entity limited); s3 (ejected entity copy).Scenario 1 on fixed tree:server/python/.venv/bin/python -m metaobjects.cli genin s1 -> exit 0, wrote Order.py, Invoice.py, order_router.py, invoice_router.py and filter-allowlist modules;python -I -c 'import gen.order_router, gen.invoice_router'-> imports ok.Scenario 1 on base tree (728f6d34) via PYTHONPATH fromgit archiveinto scratch -> exit 1,generator 'routes' requires 'entity', which is limited away from ['Base', 'Ledger'](spurious refusal reproduced before the fix).Scenario 2a/2b on fixed tree and base tree: gen exit 1 withgenerator 'routes' requires 'entity', which is limited away from ['Base']and['BridgeAuth']; no output files written.Scenario 3:metaobjects eject entity --root <s3>, theneject --force entityover identical copy -> printsunchanged entity -> codegen/generators/entity.py (already the reference), file sha256 and mtime_ns unchanged; then appended hand edit andeject --force-> replaced, sha256 back to reference.Base-tree check: sourceless object outside entity's selection still gets ledger_filter_allowlist.py from filter-allowlist on base as well, so that output is pre-existing and not in this change.Baseline (not re-run):scripts/ci-local.sh --affected --strict-toolchainspassed at 6c5d73ab4a. Covers the unit tests in test_generator_settings.py for the closure, abstract base, M:N, TPH and eject behaviour.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Validation: two no-mistakes gate runs on this branch. The first stopped at the test step because no review provider was available; its review-round fix was kept. The second passed after one review fix round (TPH subtypes added to the entity import closure, two CHANGELOG bullets).