Hi guys! Here goes the code sample:

from sqlalchemy import create_engine, MetaData
from sqlalchemy import Table, Column, ForeignKey, Integer
from sqlalchemy.orm import sessionmaker, mapper, relation

metadata = MetaData()
engine = create_engine('sqlite:///:memory:', echo=True)

parent_table = Table('parent', metadata,
    Column('id', Integer, primary_key=True))
child_table = Table('child', metadata,
    Column('id', Integer, primary_key=True),
    Column('parent_id', Integer, ForeignKey('parent.id')))

class Parent(object): pass
class Child(object): pass

mapper(Parent, parent_table, properties={'children': relation(Child,
backref=u'parent')})
mapper(Child, child_table)
metadata.create_all(engine)
session = sessionmaker(bind=engine)()
parentobj = Parent()


Running this code fails with this error:

.../SQLAlchemy-0.5.2-py2.6.egg/sqlalchemy/orm/properties.pyc in
_post_init(self)
    993
    994             if self.backref is not None:
--> 995                 self.backref.compile(self)
    996         elif not mapper.class_mapper(self.parent.class_,
compile=False)._get_property(self.key, raiseerr=False):
    997             raise sa_exc.ArgumentError("Attempting to assign a
new relation '%s' to "
AttributeError: 'unicode' object has no attribute 'compile'

This line is the problem:
    mapper(Parent, parent_table, properties={'children': relation
(Child, backref=u'parent')})
or, to be precise, `backref=u'parent'`. With just `backref='parent'`,
everything works just fine, it breaks down when using a unicode
literal for backref name. Is this a bug, or somehow expected behavior?

Thanks everyone...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to