OK then please report this as a bug in sqlalchemy-utils right now they are not looking at local table
looking at the code here: https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/functions/orm.html#get_mapper code can be like: mappers = [ mapper for mapper in all_mappers if mixed in {mapper.local_table} ] where above, using "table in set()" makes sure this compared on hash/eq rather than "is" to accommodate for Table vs. AnnotatedTable On Wed, May 26, 2021, at 11:49 AM, piotr maliński wrote: > It's from sqlalchemy_utils - > https://sqlalchemy-utils.readthedocs.io/en/latest/orm_helpers.html#get-mapper > > śr., 26 maj 2021 o 17:47 Mike Bayer <mike...@zzzcomputing.com> napisał(a): >> __ >> get_mapper() is not part of SQLAlchemy where is it? >> >> On Wed, May 26, 2021, at 9:35 AM, piotr maliński wrote: >>> AnnotatedTable doesn't have a mapper so I call: >>> >>> get_mapper(annotated_table_object_here) >>> >>> To then map a column name to a column on a model with _entity_descriptor. >>> In get_mapper this seems to hit the "if isinstance(mixed, sa.Table):" >>> branch and: >>> >>> if mixed in mapper.tables >>> >>> ends true to all 3 of them as it's either the parent or child that inherits >>> it. >>> >>> >>> >>> >>> >>> śr., 26 maj 2021 o 15:21 Mike Bayer <mike...@zzzcomputing.com> napisał(a): >>>> __ >>>> I would need to see what get_mapper() is doing. the best way to >>>> associate the relevant table to a mapper is to look at >>>> inspect(Class).mapper.local_table. >>>> >>>> >>>> >>>> On Wed, May 26, 2021, at 9:18 AM, Piotr wrote: >>>>> I'm updating "sqlalchemy_django_query" for SQLAlchemy 1.4 and aside of >>>>> that I found a peculiar problem - when I call get_mapper on a table >>>>> (AnnotatedTable) I get a ValueError due to multiple mappers found. >>>>> >>>>> The model is inherited by two other models and get_mapper finds mappers >>>>> for all 3 models due to this: >>>>> >>>>> >>>>> class Conversation(db.Base): >>>>> __tablename__ = 'conversation' >>>>> id = sqlalchemy.Column(postgres_dialect.UUID(as_uuid=True), >>>>> primary_key=True, default=uuid.uuid4) >>>>> ... >>>>> type = sqlalchemy.Column(sqlalchemy.Text, nullable=False) >>>>> >>>>> __mapper_args__ = { >>>>> 'polymorphic_identity': 'conversation', >>>>> 'polymorphic_on': type, >>>>> } >>>>> >>>>> >>>>> ... >>>>> >>>>> >>>>> class ContactFormConversation(Conversation): >>>>> __tablename__ = 'contact_form_conversation' >>>>> id = sqlalchemy.Column(sqlalchemy.ForeignKey('conversation.id'), >>>>> primary_key=True, nullable=False) >>>>> ... >>>>> >>>>> __mapper_args__ = { >>>>> 'polymorphic_identity': 'contact_form_conversation', >>>>> } >>>>> >>>>> >>>>> ... >>>>> >>>>> >>>>> class RatingConversation(Conversation): >>>>> __tablename__ = 'rating_conversation' >>>>> id = sqlalchemy.Column(sqlalchemy.ForeignKey('conversation.id'), >>>>> primary_key=True, nullable=False) >>>>> ... >>>>> >>>>> __mapper_args__ = { >>>>> 'polymorphic_identity': 'rating_conversation', >>>>> } >>>>> >>>>> >>>>> Should the model structure be done differently? >>>>> >>>>> >>>>> -- >>>>> SQLAlchemy - >>>>> The Python SQL Toolkit and Object Relational Mapper >>>>> >>>>> http://www.sqlalchemy.org/ >>>>> >>>>> To post example code, please provide an MCVE: Minimal, Complete, and >>>>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >>>>> description. >>>>> --- >>>>> You received this message because you are subscribed to the Google Groups >>>>> "sqlalchemy" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send an >>>>> email to sqlalchemy+unsubscr...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/sqlalchemy/8a86ddb1-329c-41d2-9f23-0147f8c68316n%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/sqlalchemy/8a86ddb1-329c-41d2-9f23-0147f8c68316n%40googlegroups.com?utm_medium=email&utm_source=footer>. >>>> >>>> >>>> -- >>>> SQLAlchemy - >>>> The Python SQL Toolkit and Object Relational Mapper >>>> >>>> http://www.sqlalchemy.org/ >>>> >>>> To post example code, please provide an MCVE: Minimal, Complete, and >>>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >>>> description. >>>> --- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "sqlalchemy" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/sqlalchemy/cH8L4MTVWIY/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> sqlalchemy+unsubscr...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/sqlalchemy/d953ab16-fa2b-4792-aa9e-43ee4677713c%40www.fastmail.com >>>> >>>> <https://groups.google.com/d/msgid/sqlalchemy/d953ab16-fa2b-4792-aa9e-43ee4677713c%40www.fastmail.com?utm_medium=email&utm_source=footer>. >>> >>> -- >>> SQLAlchemy - >>> The Python SQL Toolkit and Object Relational Mapper >>> >>> http://www.sqlalchemy.org/ >>> >>> To post example code, please provide an MCVE: Minimal, Complete, and >>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >>> description. >>> --- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to sqlalchemy+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/sqlalchemy/CAL_zvkSUqiJb%3DGOJrXCA9KGRspcrH%2BMBpDWE92CsFL2yP4uQvw%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/sqlalchemy/CAL_zvkSUqiJb%3DGOJrXCA9KGRspcrH%2BMBpDWE92CsFL2yP4uQvw%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> >> >> -- >> SQLAlchemy - >> The Python SQL Toolkit and Object Relational Mapper >> >> http://www.sqlalchemy.org/ >> >> To post example code, please provide an MCVE: Minimal, Complete, and >> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >> description. >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "sqlalchemy" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/sqlalchemy/cH8L4MTVWIY/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> sqlalchemy+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sqlalchemy/f887cc57-dfe3-4743-85dc-d907620eee73%40www.fastmail.com >> >> <https://groups.google.com/d/msgid/sqlalchemy/f887cc57-dfe3-4743-85dc-d907620eee73%40www.fastmail.com?utm_medium=email&utm_source=footer>. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/CAL_zvkQGaLkKNwqJT45Z%3DZbY92Txz%2BokSsKgjFqQWAy4x%3DyFpw%40mail.gmail.com > > <https://groups.google.com/d/msgid/sqlalchemy/CAL_zvkQGaLkKNwqJT45Z%3DZbY92Txz%2BokSsKgjFqQWAy4x%3DyFpw%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/c4c9a1bb-d78b-4f78-9966-687054909dcf%40www.fastmail.com.