ORM classes ending with letter "s" are not generated properly

351 views Asked by At

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?

1

There are 1 answers

0
Chris On BEST ANSWER

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.