Commit 18dc6c8
committed
feat(codegen-python): reverse navigation via explicit FK finders (ADR-0038)
Implement the Python port of ADR-0038 / ADR-0036 Wave 4: generate reverse 1:N
navigation as explicit, typed FK query finders on the repository Protocol seam,
NOT lazy ORM collections — matching the TS reference and the cross-port contract.
For each FK an entity E holds (an identity.reference over an FK field referencing
T), E's repository Protocol now gains a finder pair, named by the FK FIELD
(snake_cased, single trailing `_id` dropped) so it is unique within E by
construction:
find_<e_plural>_by_<fk_segment>(value) → single, WHERE fk = ?
find_<e_plural>_by_<fk_segment>_in(values) → batched, WHERE fk IN (…) (anti-N+1)
Both return list[Any] (the E rows matching a given T id) — a plain, framework-free
single query the consumer implements, NOT a lazy relationship() (no open session,
no N+1). The same-pair case (GameSession with 3 FKs to Scene) yields 3 distinct
finders — find_game_sessions_by_current_scene /
…_by_last_opening_narrative_scene / …_by_transitioning_from_scene — no collision
and no naming attribute.
The Python port only ever emitted M:N navigation (no lazy reverse 1:N
collections), so there is nothing to remove; M:N traversal is unchanged.
- apidocs/naming.py: reverse_finder_fk_segment / reverse_finder_fn /
reverse_finder_in_fn (the cross-port naming SSOT, idiomatic snake_case).
- router_generator.py: reverse_fks_for (derives FKs from identity.reference) +
_emit_reverse_finders extension hook, wired into the repository Protocol; the
existing _emit_repository_protocol override seam is left signature-stable.
- test_reverse_finders.py loads the shared fixtures/conformance/
reverse-finders-same-pair corpus and asserts the 3 distinct GameSession finders
+ single/batched shapes + no lazy reverse collection.
Shared fixture + goldens untouched; registry-conformance unaffected (no new vocab).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9xLEQZaPus5Y6opk398n1 parent 52d76f1 commit 18dc6c8
3 files changed
Lines changed: 352 additions & 2 deletions
File tree
- server/python
- src/metaobjects
- apidocs
- codegen/generators
- tests/codegen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
Lines changed: 73 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | | - | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
75 | 83 | | |
76 | 84 | | |
77 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
78 | 123 | | |
79 | 124 | | |
80 | 125 | | |
| |||
88 | 133 | | |
89 | 134 | | |
90 | 135 | | |
| 136 | + | |
| 137 | + | |
91 | 138 | | |
92 | 139 | | |
93 | 140 | | |
| |||
127 | 174 | | |
128 | 175 | | |
129 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
130 | 199 | | |
131 | 200 | | |
132 | 201 | | |
| |||
538 | 607 | | |
539 | 608 | | |
540 | 609 | | |
541 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
542 | 613 | | |
543 | 614 | | |
544 | 615 | | |
| |||
0 commit comments