Skip to content

fix(cli): honor per-entity table override in Python and Go generators (#107) - #119

Open
cultron wants to merge 1 commit into
mainfrom
fix/107-python-go-table-override
Open

fix(cli): honor per-entity table override in Python and Go generators (#107)#119
cultron wants to merge 1 commit into
mainfrom
fix/107-python-go-table-override

Conversation

@cultron

@cultron cultron commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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-entity table override in .apsorc. An entity named Order with "table": "order_record" generated the SQL reserved word order in both languages.

Fix

  • Both generators now surface 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).
  • Go (templates/go/models/model.eta): TableName() returns tableName.
  • Python (templates/python/models/model.eta): tableName is used for __tablename__ and for every other place that names this entity's own table — the self-referencing ManyToMany ForeignKey("<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 uses assoc.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:

  • override honored → order_record, never the reserved word order
  • no override → default order preserved

Full suite: 318 passed / 0 failed, lint 0 errors.

Note

Merging to main publishes @apso/cli (merge = release) — leaving the merge to Matt.

🤖 Generated with Claude Code

…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python and Go generators ignore per-entity table override (parity with #98)

1 participant