Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child table ORM classes inheriting from base tables are not generated #336

Open
2 tasks done
kiitosu opened this issue Jun 19, 2024 · 5 comments
Open
2 tasks done
Labels

Comments

@kiitosu
Copy link

kiitosu commented Jun 19, 2024

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Sqlacodegen version

3.0.0rc5

SQLAlchemy version

2.0.29

RDBMS vendor

PostgreSQL

What happened?

When using sqlacodegen to generate ORM classes from an existing database schema, the child table ORM classes that inherit from base tables are not created. This issue occurs when there are tables using SQLAlchemy inheritance.

Is there any way to codegen child tables?

Database schema for reproducing the bug

Up migrateion to reproduce is like below.

create schema "test";

CREATE TABLE "test"."base" ("base" integer NOT NULL, PRIMARY KEY ("base") );COMMENT ON TABLE "test"."base" IS E'base';

CREATE TABLE test.sub (
    sub_data integer
) INHERITS (test.base);

Generated code.

# Using geoalchemy2 0.14.7
from sqlalchemy import Column, Integer, PrimaryKeyConstraint, Table
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

class Base(DeclarativeBase):
    pass


class Base(Base):
    __tablename__ = 'base'
    __table_args__ = (
        PrimaryKeyConstraint('base', name='base_pkey'),
        {'comment': 'base', 'schema': 'test'}
    )

    base: Mapped[int] = mapped_column(Integer, primary_key=True)


t_sub = Table(
    'sub', Base.metadata,
    Column('base', Integer, nullable=False),
    Column('sub_data', Integer),
    schema='test'
)
@kiitosu kiitosu added the bug label Jun 19, 2024
@agronholm
Copy link
Owner

Please provide a sample schema and the code generated from it.

@kiitosu
Copy link
Author

kiitosu commented Jun 20, 2024

@agronholm
Thank you for your replay.
I added information, please check it!

@agronholm
Copy link
Owner

OK, so by "SQLAlchemy inheritance" you really meant PostgreSQL inheritance. The two are totally different concepts. SQLACodegen has never been tested against PostgreSQL inheritance, and I don't think SQLAlchemy's reflection can even detect that, and as a consequence, SQLACodegen would not know about it either.

@kiitosu
Copy link
Author

kiitosu commented Jun 20, 2024

@agronholm
Thank you for the explanation. Indeed, it is PostgreSQL inheritance. So, it's not a bug, is it? Is it possible to make a feature request? Would it be necessary to consult with SQLAlchemy first since their support is required?

@agronholm
Copy link
Owner

Check with upstream SQLAlchemy first. The use of database-side inheritance is not a common usage pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants