you no longer have to use DeclarativeMeta at all, you can use a class decorator:
https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#declarative-mapping-using-a-decorator-no-declarative-base if you are on 1.3, there's a way to get the same effect in 1.3 using the instrument_declarative function: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html?highlight=instrument_declarative#sqlalchemy.ext.declarative.instrument_declarative which can be turned into an equivalent decorator. that said I have not yet experimented with mapping classes that are also extending ABCMeta so I'm not sure if there are other issues. On Sun, Mar 14, 2021, at 8:53 PM, Richard Damon wrote: > I have a lot of tables that have some similar functionality that I would > like to factor out into a base mix-in class that provides some common > methods. Some of these methods will want to use a method that must be > defined in the actual table ORM class, and would be an abstract method > in the base. If you just blindly do this you get the Python error of > multiple metaclasses, so I need to define a metaclass that inherets from > both ABCMeta and DeclarativeMeta, and then the Table ORM classes need to > mention declarative_base, the mixin and metaclass=mymeta. This works but > looks wordy. > > If instead I try to put the mix-in between declarative_base and the > table class in the heirarchy, SQLAlchemy complains that it is missing > information for it to be a table (which is correct). If I put it as a > base to declarative_base the SQLAlchemy gets errors that it needs to > implement the abstract methods (and I of course can only do this once). > > I could make the mixin not use the ABCMeta as its metaclass, but then if > I forget to define the abstract method in the table, I get no > complaints, at best I could catch the call to the abstract method > because it wasn't overridden. > > Is this the way it is supposed to work, or am I missing some other trick? > > Side question, when doing this sort of mix-in, does the order of the > mix-in and declarative_base matter, or is there a real preference? > > -- > Richard Damon > > -- > 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/e8d4c401-95fe-957f-7d65-3e37cd5150c6%40Damon-Family.org. > -- 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/1f4f4ffc-d7dc-4ead-b031-a1e77c13586a%40www.fastmail.com.