fix(cli): honor per-entity table override in Python and Go generators (#107) - #119
Open
cultron wants to merge 1 commit into
Open
fix(cli): honor per-entity table override in Python and Go generators (#107)#119cultron wants to merge 1 commit into
cultron wants to merge 1 commit into
Conversation
…#107) Parity with #98/#106 (TypeScript). The Python and Go generators derived the table name as snakeCase(entity.name) and never read the per-entity `table` override, so an entity named `Order` with "table": "order_record" generated the SQL reserved word `order`. - Both generators now emit `tableName = entity.table || snakeCase(name)`. - Python template uses it for `__tablename__`, the self-referencing ManyToMany ForeignKey, join-table names, and index names, so every reference to this entity's own table follows the override consistently. - Go template uses it in `TableName()`. Without an override tableName === snakeCase(name), so output is unchanged for the common case. Added override + fallback tests to both suites. Full suite: 318 passed, 0 failed. fixes #107
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.
Fixes #107 — Python/Go parity with #98/#106 (already fixed for TypeScript).
Problem
The Python and Go generators derived the table name as
snakeCase(entity.name)and never read the per-entitytableoverride in.apsorc. An entity namedOrderwith"table": "order_record"generated the SQL reserved wordorderin both languages.Fix
tableName = entity.table || snakeCase(name)into the template context (mirrors the TS fix in fix(cli): honor per-entity table override in TS generator (#98) #106).templates/go/models/model.eta):TableName()returnstableName.templates/python/models/model.eta):tableNameis used for__tablename__and for every other place that names this entity's own table — the self-referencing ManyToManyForeignKey("<table>.id"), the derived join-table name, the join-column prefix, and the index name. This matters in SQLAlchemy (unlike TypeORM) because the join-table FK references the owning table by string name; if only__tablename__changed, that FK would point at a non-existent table.Without an override
tableName === snakeCase(name), so generated output is byte-identical for the common (no-override) case. The only behavior change is when an override is set, and then all self-table references follow it consistently.Scope note
Cross-entity FKs to other entities' tables (e.g. Python
ForeignKey("<assoc>.id"), which already usesassoc.name.toLowerCase()rather than the override) are a separate pre-existing gap and are intentionally out of scope here, matching #106's focus.Tests
Added override + fallback tests to both generator suites:
order_record, never the reserved wordorderorderpreservedFull suite: 318 passed / 0 failed, lint 0 errors.
Note
Merging to
mainpublishes@apso/cli(merge = release) — leaving the merge to Matt.🤖 Generated with Claude Code