2

I'm using SQLAlchemy and sqlacodegen to generate ORM classes for my PostgreSQL models. But to my surprise, tables ending with letter "s" are causing issue.

For example, I have a table as below

employee_status

and the ORM class generated for this table is as below

Class EmployeeStatu(Base):
    __tablename__ = "employee_status"
    col1 = Column(String(32))

Why is the ending letter "s" missing in class name when it is present in table name?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
newbie
  • 1,282
  • 3
  • 20
  • 43
  • looks like the bug, but may be the author of the utility you use try to generate python class in the singular. – Brown Bear Sep 19 '19 at 12:09
  • 2
    Most likely it has to do with pluralization of table names. Check how to configure pluralization for SQLAlchemy. – sid-m Sep 19 '19 at 12:10
  • 2
    https://github.com/agronholm/sqlacodegen#model-class-naming-logic read the section `Model class naming logic` – Brown Bear Sep 19 '19 at 12:11

1 Answers1

5

sqlacodegen doesn't do this itself:

Model class naming logic

The table name (which is assumed to be in English) is converted to singular form using the "inflect" library. Then, every underscore is removed while transforming the next letter to upper case. For example, sales_invoices becomes SalesInvoice.

This appears to have already been reported as a bug in that library. In the meantime nothing is stopping you from correcting the class name manually.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257