Code

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1459 closed defect (fixed)

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

Reported by: matt Owned by: adrian
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: UI/UX:

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@…> 8 years ago.
Fix many-to-many relations for SQLite (without breaking others)

Download all attachments as: .zip

Change History (5)

comment:1 Changed 8 years ago by Malcolm Tredinnick <malcolm@…>

  • Summary changed from [magic-removal] m2m problems with SQLite to [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.

Changed 8 years ago by Malcolm Tredinnick <malcolm@…>

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

comment:2 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:3 Changed 8 years ago by anonymous

  • priority changed from normal to highest

comment:4 Changed 7 years ago by adrian

  • milestone Version 0.92 deleted

Milestone Version 0.92 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.