Hi all,
I'm using a class factory to dynamically generate SQLA types and am rightfully getting the warning:
SAWarning: This declarative base already contains a class with the same class name and module name as <module.class_name>, and will be replaced in the string-lookup table.
when I attempt to use it twice for the same parameters. But, what I was hoping to do was use said string-lookup table (which I can't seem to find in base.metadata or elsewhere) in my class factory such that I can call it as many times as I want (instead of using it once and keeping a reference), and it would return a reference to that already-created class instead of generating the identical new one and the subsequent warning.
Essentially I'd like something like:
def create_cls(cls_name, tablename):
if cls_name in Base.metadata.string_lookup_table:
return Base.metadata.string_lookup_table[cls_name]
<....>
return type(cls_name, (Base,), some_dynamic_attrs_n_stuff)
The given answer
here generates an error for Base not having an _decl_class_registry attribute (I'm using 1.4.3 if that helps), though any solution that uses the tablename or class/module name will work for my case.
Thanks,
Brendan