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
SAWarning: SELECT statement has a cartesian product between FROM element(s) #305
Comments
This seem to be happening due to a change in SQLA from this thread, Edit: |
I think I am probably experiencing the same thing. I get the warning but as far as I can tell it isn't a problem as the output is exactly what I intended. The schema: class MediaType(Base):
__tablename__ = "media_types"
media_type: Mapped[str] = mapped_column(init=True, primary_key=True)
file_format: Mapped[str] = mapped_column(
default=None, unique=True, nullable=True
)
class Collection(Base):
__tablename__ = "collections"
collection_id: Mapped[int] = mapped_column(
init=False, primary_key=True, autoincrement=True
)
collection_name: Mapped[str] = mapped_column(default=None)
collection_description: Mapped[str] = mapped_column(
default=None, unique=False, nullable=True
)
media_type_id: Mapped[str] = mapped_column(
"media_type",
ForeignKey("media_types.media_type"), default=None
)
media_type: Mapped[MediaType] = relationship(init=False)
collection_ezname: Mapped[str] = mapped_column(Computed(func.LOWER(func.REGEXP_REPLACE((collection_name), '[ /%<>#";?:@&=+$,.]', '_', 'g'))), unique=True, init=False)
tags: Mapped[list] = mapped_column(ARRAY(TEXT, dimensions=1), default=None, nullable=True)
date_added: Mapped[datetime.datetime] = mapped_column(default=None, nullable=True)
__mapper_args__ = {
"polymorphic_identity": "collections",
"eager_defaults": True,
}
class Post(Base):
__tablename__ = "posts"
id: Mapped[int] = mapped_column(init=False, primary_key=True)
title: Mapped[str] = mapped_column(default=None, nullable=True)
description: Mapped[str] = mapped_column(default=None, nullable=True)
collection_id: Mapped[int] = mapped_column(
ForeignKey("collections.collection_id"), init=False
)
collection: Mapped[Collection] = relationship(kw_only=True)
media_type: Mapped[str] = mapped_column(
ForeignKey("media_types.media_type"), init=False
)
media_type_reference: Mapped[MediaType] = relationship(init=False)
tags: Mapped[list] = mapped_column(ARRAY(TEXT, dimensions=1), default=None, nullable=True)
views: Mapped[int] = mapped_column(default=0, nullable=True)
social_media: Mapped[dict] =mapped_column(JSONB, default=None, nullable=True)
date_added: Mapped[datetime.datetime] = mapped_column(default=None, nullable=True)
date_modified: Mapped[datetime.datetime] = mapped_column(default=None, nullable=True)
rss_pub_date: Mapped[str] = mapped_column(default=None, nullable=True)
added_to_rss: Mapped[bool] = mapped_column(default=False, nullable=True)
__mapper_args__ = {
"polymorphic_identity": "posts",
"polymorphic_on": "media_type",
"eager_defaults": True,
}
class Link(Post):
__tablename__ = "links"
id: Mapped[int] = mapped_column(
ForeignKey("posts.id"), init=False, primary_key=True
)
url: Mapped[str] = mapped_column(default=None, unique=True)
other_info: Mapped[str] = mapped_column(default=None, nullable=True)
clicks: Mapped[int] = mapped_column(default=0, nullable=True)
__mapper_args__ = {
"polymorphic_identity": "links",
"eager_defaults": True,
} The line that makes the error: link_collections = db.session.query(Collection).where(MediaType.media_type == "links").all()
print(link_collections) The output (which, I stress, was the output I desired): [Collection(collection_id=1, collection_name='Essentials', collection_description='', media_type_id='links', media_type=MediaType(media_type='links', file_format=None), collection_ezname='essentials', tags=None, date_added=None), Collection(collection_id=2, collection_name='NYC', collection_description='', media_type_id='links', media_type=MediaType(media_type='links', file_format=None), collection_ezname='nyc', tags=None, date_added=None), Collection(collection_id=3, collection_name='Amazing Art', collection_description='', media_type_id='links', media_type=MediaType(media_type='links', file_format=None), collection_ezname='amazing_art', tags=None, date_added=None),
....
] |
Getting this warning when running pytest
tests/relationships/test_non_versioned_classes.py::TestManyToManyRelationshipToNonVersionedClass::test_single_insert
I created a normal py-script from testfile to replicate the issue
Logs:
This seem to be to happening only for SQLA > 1.4
The text was updated successfully, but these errors were encountered: