I get three failing m2m-related tests on magic-removal [2475] using OSX 10.4.5, SQLite 3.1.3 and PySQLite 2.0.7:
'm2m_recursive' module: API test raised an exception
====================================================
Code: 'b.friends.add(a)'
Line: 34
Exception: File "/Users/mcroydon/django/django_magic/tests/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest m2m_recursive[14]>", line 1, in ?
b.friends.add(a)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 365, in add
target_col_name, instance._get_pk_val(), *objs)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 233, in _add_m2m_items
[source_pk_val, obj_id])
File "/Users/mcroydon/django/django_magic/django/db/backends/util.py", line 11, in execute
result = self.cursor.execute(sql, params)
File "/Users/mcroydon/django/django_magic/django/db/backends/sqlite3/base.py", line 63, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: columns from_person_id, to_person_id are not unique
'm2m_recursive' module: API test raised an exception
====================================================
Code: 'b.stalkers.add(a)'
Line: 115
Exception: File "/Users/mcroydon/django/django_magic/tests/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest m2m_recursive[35]>", line 1, in ?
b.stalkers.add(a)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 307, in add
target_col_name, instance._get_pk_val(), *objs)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 233, in _add_m2m_items
[source_pk_val, obj_id])
File "/Users/mcroydon/django/django_magic/django/db/backends/util.py", line 11, in execute
result = self.cursor.execute(sql, params)
File "/Users/mcroydon/django/django_magic/django/db/backends/sqlite3/base.py", line 63, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: columns from_person_id, to_person_id are not unique
'many_to_many' module: API test raised an exception
===================================================
Code: 'a2.publications.add(p3)'
Line: 23
Exception: File "/Users/mcroydon/django/django_magic/tests/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest many_to_many[13]>", line 1, in ?
a2.publications.add(p3)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 365, in add
target_col_name, instance._get_pk_val(), *objs)
File "/Users/mcroydon/django/django_magic/django/db/models/fields/related.py", line 233, in _add_m2m_items
[source_pk_val, obj_id])
File "/Users/mcroydon/django/django_magic/django/db/backends/util.py", line 11, in execute
result = self.cursor.execute(sql, params)
File "/Users/mcroydon/django/django_magic/django/db/backends/sqlite3/base.py", line 63, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: columns article_id, publication_id are not unique
Turns out this has been broken for almost a month. Changeset r2289 combined with SQLite is the problem. In SQLite there is no way to determine the number of rows affected by a SELECT statement without retrieving the rows. Consequently, the cursor.rowcount attribute cannot be set in pysqlite2 (well, it is correctly set to -1). I will attach a patch that fixes this.