You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BaseModelForm = model_form_factory(ModelForm_)
class ModelForm(BaseModelForm):
class Meta:
include_primary_keys = True
include_foreign_keys = True
@classmethod
def get_session(self): # noqa
return DBSession
parent.py
from sqlalchemy import Column, Integer
from sqlalchemy.orm import relationship
from . import Base, ModelForm
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relationship("Child", back_populates="parent")
class MapForm(ModelForm):
class Meta:
model = Parent
child.py
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from . import Base
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parent.id'))
parent = relationship("Parent", back_populates="children")
Status API Training Shop Blog About Pricing
It breaks initializing with the following error message:
File "/Users/user/.virtualenvs/temp/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py", line 1601, in mapper
argument = self.argument()
File "/Users/user/.virtualenvs/temp/lib/python2.7/site-packages/sqlalchemy/ext/declarative/clsregistry.py", line 293, in __call__
(self.prop.parent, self.arg, n.args[0], self.cls)
sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|Parent|parent, expression 'Child' failed to locate a name ("name 'Child' is not defined"). If this is a class name, consider adding this relationship() to the <class 'pyramidsqlalchemyrelationshipbug.models.parent.Parent'> class after both dependent classes have been defined.
Basically, having model definitions like this:
init.py
parent.py
child.py
It breaks initializing with the following error message:
I made a repo out of a minimal project:
https://github.com/hyperknot/pyramid-sqlalchemy-wtforms-relationship-bug
The text was updated successfully, but these errors were encountered: