- changed status to resolved
error in declarative adjacency lit relationship (in 0.5.0rc4)
Issue #1255
resolved
I have a CMS page model which looks like this:
class Page(BaseObject):
"""A page in the CMS."""
__tablename__ = "page"
id = schema.Column(types.Integer(), primary_key=True, autoincrement=True)
path = schema.Column(types.Unicode(128), nullable=False, index=True)
parent_id = schema.Column(types.Integer(),
schema.ForeignKey("page.id", onupdate="CASCADE", ondelete="CASCADE"),
nullable=False, index=True)
children = orm.relation("Page", cascade="all",
backref=orm.backref("parent", remote_side=["page.id"]("page.id")),
collection_class=attribute_mapped_collection("path"))
this apears to work fine and the table is correct created in the database. However on the first query I do in that database for a completely unrelated object I get this:
File "/Users/wichert/Development/2style4you/code/buildout/devel/src/2style4you/2style4you/websetup.py", line 21, in setup_app
existing_accounts=[for account in meta.Session.query(Editor)](account.login)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/scoping.py", line 121, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/session.py", line 908, in query
return self._query_cls(entities, self, **kwargs)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/query.py", line 95, in __init__
self.__setup_aliasizers(self._entities)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/query.py", line 109, in __setup_aliasizers
mapper, selectable, is_aliased_class = _entity_info(entity)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/util.py", line 466, in _entity_info
mapper = class_mapper(entity, compile)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/util.py", line 543, in class_mapper
mapper = mapper.compile()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py", line 679, in compile
mapper._post_configure_properties()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py", line 701, in _post_configure_properties
prop.init(key, self)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/interfaces.py", line 404, in init
self.do_init()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py", line 579, in do_init
self._post_init()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py", line 838, in _post_init
self.backref.compile(self)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py", line 989, in compile
mapper._compile_property(self.key, relation);
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py", line 643, in _compile_property
prop.init(key, self)
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/interfaces.py", line 404, in init
self.do_init()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py", line 578, in do_init
self._determine_local_remote_pairs()
File "/Users/wichert/Library/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py", line 814, in _determine_local_remote_pairs
self.local_side, self.remote_side = [for x in zip(*list(self.local_remote_pairs))](util.OrderedSet(x))
ValueError: need more than 0 values to unpack
I put a pdb.set_trace()
in there to see what self looked like:
(Pdb) p self
<sqlalchemy.orm.properties.PropertyLoader object at 0x26ed950>
(Pdb) pp self.__dict__
{'_PropertyLoader__join_cache': {},
'_compiled': True,
'_creation_order': 498,
'_foreign_keys': set([Integer(), ForeignKey('page.id'), table=<page>, nullable=False)](Column('parent_id',)),
'_is_backref': True,
'_reverse_property': None,
'argument': <Mapper at 0x24c5970; Page>,
'backref': <sqlalchemy.orm.properties.BackRef object at 0x26ed910>,
'cascade': CascadeOptions('save_update,merge'),
'collection_class': None,
'comparator': <sqlalchemy.orm.properties.Comparator object at 0x26ed970>,
'comparator_factory': <class 'sqlalchemy.orm.properties.Comparator'>,
'direction': <symbol 'MANYTOONE>,
'enable_typechecks': True,
'extension': None,
'join_depth': None,
'key': 'parent',
'lazy': True,
'local_remote_pairs': ['mapper': <Mapper at 0x24c5970; Page>,
'order_by': False,
'parent': <Mapper at 0x24c5970; Page>,
'passive_deletes': False,
'passive_updates': True,
'post_update': False,
'primaryjoin': <sqlalchemy.sql.expression._BinaryExpression object at 0x26eda10>,
'remote_side': set([<sqlalchemy.sql.expression._ColumnClause at 0x26eda30; page.id>](],
)),
'secondary': None,
'secondary_synchronize_pairs': None,
'secondaryjoin': None,
'strategy_class': <class 'sqlalchemy.orm.strategies.LazyLoader'>,
'synchronize_pairs': [Integer(), table=<page>, primary_key=True, nullable=False),
Column('parent_id', Integer(), ForeignKey('page.id'), table=<page>, nullable=False))]((Column('id',),
'table': Table('page', MetaData(Engine(postgres://2style4you@/2style4you)), Column('id', Integer(), table=<page>, primary_key=True, nullable=False), Column('path', Unicode(length=128), table=<page>, nullable=False), Column('parent_id', Integer(), ForeignKey('page.id'), table=<page>, nullable=False), schema=None),
'target': Table('page', MetaData(Engine(postgres://2style4you@/2style4you)), Column('id', Integer(), table=<page>, primary_key=True, nullable=False), Column('path', Unicode(length=128), table=<page>, nullable=False), Column('parent_id', Integer(), ForeignKey('page.id'), table=<page>, nullable=False), schema=None),
'uselist': None,
'viewonly': False}
the problem appears to be in the backref of the children relation: as soon as I remove that things work fine.
Comments (1)
-
repo owner - Log in to comment
remote_side="[Page.id](Page.id)"
, orremote_side="Page.id"