ah ill take a look, it is definitely sensitive to recursion issues which I thought i had fixed but I will try that one out. the remove () issue is probably just a method that I am not covering properly. I also might want to look more closely at the case where, you loaded object A, object B has the list still triggered to be lazy- loaded...then deleting from A, does that trigger the lazy load on B before trying to remove the item ? its a pretty intricate situation.

It might be enlightening if you tried out some of your test cases within the AttributesTest.testbackref test in the attributes.py test suite. This test suite is not using any mappers or database access, just strictly the "attributes" package which supplies the property decorators on classes, and the many-to-many test deals with pretty much one object called a ListBackrefExtension, that talks to two HistoryList objects. its a pretty focused test on just this whole "circular relationship" idea.

On Dec 14, 2005, at 7:47 PM, Robert Leftwich wrote:

Michael Bayer wrote:
hey folks -
I just checked in the "backref" feature.

There is a recursion problem when deleting items out of a m:n mapped relationship:

studentTbl = Table('student', engine, Column ('name', String, primary_key=True)) courseTbl = Table('course', engine, Column ('name', String, primary_key=True))
enrolTbl = Table('enrol', engine,
Column('student_id', String, ForeignKey ('student.name'), primary_key=True), Column('course_id', String, ForeignKey ('course.name'), primary_key=True))
class Student(object):
        def __init__(self, name=''):
        self.name = name
        class Course(object):
        def __init__(self, name=''):
        self.name = name
Student.mapper = mapper(Student, studentTbl)
Course.mapper = mapper(Course, courseTbl, properties = {'students': relation(Student.mapper, enrolTbl, lazy=True, backref='courses')})
studentTbl.create()
courseTbl.create()
enrolTbl.create()
s1 = Student('Student1')
c1 = Course('Course1')
c2 = Course('Course2')
c3 = Course('Course3')
s1.courses.append(c1)
s1.courses.append(c2)
c1.students.append(s1)
c3.students.append(s1)
assert len(s1.courses) == 3
assert len(c1.students) == 1
objectstore.commit()
objectstore.clear()
s = Student.mapper.get_by(name='Student1')
c = Course.mapper.get_by(name='Course3')
assert len(s.courses) == 3
del s.courses[1]
assert len(s.courses) == 2
... RuntimeError: maximum recursion depth exceeded...


Also, there are some instances when I delete an item that I'm getting the following error:

IndexError: list assignment index out of range
Traceback:
  ....
File "/home/robert/tools/python/sqlalchemy/lib/sqlalchemy/ util.py", line 259, in __delitem__
    del self.data[i]

but I haven't been able to distil it down to a small test case as yet - it always triggers the recursion problem.

Lastly, if I use remove() instead of del in the first test, i.e.

assert len(s.courses) == 3
s.courses.remove(c2)
assert len(s.courses) == 2

There is no recursion error, but the last assertion fails, i.e. the remove() hasn't actually removed c2.

Hopefully, these problems are all related (excuse the pun:-))

Robert



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to