Closed leavittx closed 9 years ago
Correct. This is known albeit not well documented issue. The problem is that TreeManager needs to be added to the class after the table is defined, but before the mapper. The declarative API's Base metaclass does all this in one step.
There is probably a way around this, but since we no longer user orm-tree in production (because we no longer use SQLAlchemy, not because of any problem with the code), I haven't had the time to properly look into this. A pull request would be welcome.
PS: I know this is just an example, but I would not recommend check_same_thread with sqlite.
Wait, I could have been more helpful. There is a solution: just add the following fields to your class.
tree_id = Column(TreeIdType, nullable=False)
left = Column(TreeLeftType, nullable=False)
right = Column(TreeRightType, nullable=False)
depth = Column(TreeDepthType, nullable=False)
These column types are found in sqlalchemy_tree.types
. You can give the columns whatever names you like (their presence is auto-detected from the column type).
The original failure is that these columns were being added after the mapper was initialized, and therefore weren't mapped. Defining them explicitly obviously solves that, albeit by removing some of the magic of TreeManager.
It seems like it's not possible to use recently introduced declarative table description syntax (http://docs.sqlalchemy.org/ru/latest/orm/extensions/declarative.html) with sqlalchemy-orm-tree extension!
My code goes like that:
Which gives the following traceback:
So I guess the problem might be that code executed by line
isn't working correctly.