Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#1459 closed defect (fixed)

[patch] [magic-removal] m2m problems with SQLite

Reported by: matt Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Attachments (1)

m2m-fix.diff (644 bytes ) - added by Malcolm Tredinnick <malcolm@…> 18 years ago.
Fix many-to-many relations for SQLite (without breaking others)

Download all attachments as: .zip

Change History (5)

comment:1 by Malcolm Tredinnick <malcolm@…>, 18 years ago

Summary: [magic-removal] m2m problems with SQLite[patch] [magic-removal] m2m problems with SQLite

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.

by Malcolm Tredinnick <malcolm@…>, 18 years ago

Attachment: m2m-fix.diff added

Fix many-to-many relations for SQLite (without breaking others)

comment:2 by Russell Keith-Magee, 18 years ago

Resolution: fixed
Status: newclosed

(In [2478]) magic-removal: Fixes #1459 -- Modified the way the row count is compared to accommodate SQLite. Thanks, Malcolm Tredinnick.

comment:3 by anonymous, 18 years ago

priority: normalhighest

comment:4 by Adrian Holovaty, 18 years ago

milestone: Version 0.92

Milestone Version 0.92 deleted

Note: See TracTickets for help on using tickets.
Back to Top