Hi,

I'm using SQLAlchemy and am generating classes dynamically for my database 
via the Automapping functionality 
<https://docs.sqlalchemy.org/en/13/orm/extensions/automap.html>.

I need to add a Mixin class with various helper methods to each of these 
automapped classes.

I tried to create subclasses of the automapped class with the mixin class:
*db = create_engine(connection_string) *
*automapper = automap_base() *
*automapper.prepare(db, reflect=True) *
*for class_variable in automapper.__subclasses__(): *
*    new_class = type(class_variable.__name__, (class_variable, Mixins), 
{}) *

but when I try to use these classes I get errors like:
*class _ is a subclass of AutomapBase. Mappings are not produced until the 
.prepare() method is called on the class hierarchy. *

If I call automapper.prepare() again, I get warnings like this and mostly 
just enters an infinite loop:
*SAWarning: This declarative base already contains a class with the same 
class name and module name as sqlalchemy.ext.automap.payments, and will be 
replaced in the string-lookup table. *

I cannot specify the database classes explicitly 
<https://docs.sqlalchemy.org/en/13/orm/extensions/automap.html#specifying-classes-explicitly>
 
as in the documentation, because I don't know the database tables ahead of 
time (I'll be connecting to databases dynamically given a connection 
string).

Any thoughts?

thank you

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/6f87255c-52a9-4998-a012-2e43a538fb7en%40googlegroups.com.

Reply via email to