> To unsubscribe from this group and stop receiving emails from it, send an email to sqlal...@googlegroups.com.
@Simon.Interesting point. I create the DB and the instances in one script. The data in the db seems to be correct.However the error occurs in a second script which almost is like this:import ClassA2... create session ...objectA2 = session.query(ClassA2).first()for objectA1 in objectA2.list_objectA1:objectA1.do_something()So, no here I don't import ClassA1, but I shouldn't, should I (?).The error occurs on entering the for loop.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/a4af5e8f-d17a-4fd8-a0d4-5fb6a058b998%40googlegroups.com.
SQLAlchemy has to know about all the classes before you do a query that's going to refer to a remote class' polymorphic_identity, so somewhere you have to make sure the module was imported.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexebd5F9HXSX_kcBCY3Xey9aiPLThLX3h6GD1v7bomXd%3Dg%40mail.gmail.com.
In Python, modules are executed when they are imported. Classdefinitions are executable statements, where the metaclass is calledto construct the *class*. When you import a module containingdeclarative classes, the SQLAlchemy metaclass is called for each ofthose classes, building the mappings, registering the polymorphicidentities and so on.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexebd5F9HXSX_kcBCY3Xey9aiPLThLX3h6GD1v7bomXd%3Dg%40mail.gmail.com.
class Meta(type):
print("Here is Meta")
def __new__(cls, name, bases, dct):
print("meta.new")
return super().__new__(cls, name, bases, dct)
class Foo(metaclass=Meta):
print("Here is Foo")
from x import Foo
class What(Foo):
print("Here's What, a Foo")