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 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/d953ab16-fa2b-4792-aa9e-43ee4677713c%40www.fastmail.com.

Reply via email to