I have two classes, Artwork and Person. Artwork has a relationship to Person.

However, when I try to use them, I get an error thrown:

InvalidRequestError: When initializing mapper Mapper|Artwork|artwork, 
> expression 'Person' failed to locate a name ("name 'Person' is not 
> defined"). If this is a class name, consider adding this relationship() to 
> the <class 'model.Artwork'> class after both dependent classes have been 
> defined.



Here are the classes themselves, defined in model/__init__.py

class Artwork(db.Model, SimpleSerializeMixin):
    id = db.Column(db.Integer, primary_key=True)
    ....
    artist_id = db.Column(db.String(256), db.ForeignKey('person.sub'))
    artist = db.relationship('Person', backref='artworks')


class Person(db.Model, SimpleSerializeMixin):
    sub = db.Column(db.String(256), primary_key=True)



I checked with debugger and in sqlalchemy/ext/declarative/clsregistry.py 
(_class_resolver.__call__())
there is a line:
x = eval(self.arg, globals(), self._dict)
No "Person" or "Artwork" or any other class defined in the file are present 
in globals(). self._dict is empty
So it fails with an NameError exception.

What could be the issue ?

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to