Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20399 closed Bug (worksforme)

DatabaseError when saving model with ManyToManyField in admin

Reported by: s@… Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal Keywords: DatabaseError
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When attempting to save a model which has a ManyToManyField in the admin interface I consistently get "DatabaseError: unable to open database file" (Traceback below). The ManyToManyField hasn't been changed, it has one value selected.

This seems to be due to an attempt to resubmit the ManyToManyField to it's table.

The local variables at the bottom of the traceback are:

e: OperationalError('unable to open database file',)
self: <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0xfeafa52c>
params: (17, 2)
query: u'INSERT INTO "markets_trace_cities" ("trace_id", "city_id") SELECT ? AS "trace_id", ? AS "city_id"'

The query shouldn't be happening as the manytomanyfield hasn't been changed at all.

As well as the actual error, the error message reported is wrong, or at least unhelpful as I'm not having problems opening the database file.

Let me know if I've missed something.

Django Version: 1.5.1
Python: 2.7.3
OS: Windows 7 with python etc. installed under cygwin.
browser: Chrome, version 26.0.1410.64 m

Full Traceback:

Traceback (most recent call last):

File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response

response = callback(request, *callback_args, callback_kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/options.py", line 372, in wrapper

return self.admin_site.admin_view(view)(*args, kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view

response = view_func(request, *args, kwargs)

File "/usr/lib/python2.7/site-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func

response = view_func(request, *args, kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 202, in inner

return view(request, *args, kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in _wrapper

return bound_func(*args, kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view

response = view_func(request, *args, kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 21, in bound_func

return func(self, *args2, kwargs2)

File "/usr/lib/python2.7/site-packages/django/db/transaction.py", line 223, in inner

return func(*args, kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1106, in change_view

self.save_related(request, form, formsets, True)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/options.py", line 762, in save_related

form.save_m2m()

File "/usr/lib/python2.7/site-packages/django/forms/models.py", line 84, in save_m2m

f.save_form_data(instance, cleaned_data[f.name])

File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1336, in save_form_data

setattr(instance, self.attname, data)

File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 912, in set

manager.add(*value)

File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 650, in add

self._add_items(self.source_field_name, self.target_field_name, *objs)

File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 739, in _add_items

for obj_id in new_ids

File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 444, in bulk_create

self._batched_insert(objs_without_pk, fields, batch_size)

File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 902, in _batched_insert

using=self.db)

File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 215, in _insert

return insert_query(self.model, objs, fields, kwargs)

File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 1661, in insert_query

return query.get_compiler(using=using).execute_sql(return_id)

File "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 937, in execute_sql

cursor.execute(sql, params)

File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute

return self.cursor.execute(sql, params)

File "/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 366, in execute

six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])

File "/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute

return Database.Cursor.execute(self, query, params)

DatabaseError: unable to open database file ManyToManyField.

Attachments (1)

sampleproject.zip (13.6 KB ) - added by s@… 12 years ago.
sample project showing error

Download all attachments as: .zip

Change History (5)

comment:1 by Simon Meers, 12 years ago

Resolution: needsinfo
Status: newclosed

Could you please provide more information on how to reproduce this error, including a minimal sample project, or at least your settings module?

by s@…, 12 years ago

Attachment: sampleproject.zip added

sample project showing error

comment:2 by s@…, 12 years ago

Resolution: needsinfo
Status: closednew

I've uploaded a project showing the bug. Fust open a tree and save it without changing the manytomany for forest and it'll spring the error message, or at least it definitely does for me.

comment:3 by Simon Meers, 12 years ago

Resolution: worksforme
Status: newclosed

I've uploaded a project showing the bug.

Brilliant, thank you.

open a tree and save it without changing the manytomany for forest and it'll spring the error message, or at least it definitely does for me.

Seems to work fine here: "The tree "maple" was changed successfully. You may edit it again below."

There must be something strange in your local configuration? It seems SQLite can do some very strange things -- have a look at / this, for example.

comment:4 by s@…, 12 years ago

Humm, sqlite3.version says 2.6.0 (is that how django communicates with sqlite???), cygwin setup says I have version 3.7.16.2-1 of libsqlite3_0 installed.

I'll leave this closed as I agree it's probably a specific issue to my setup. However if anyone else finds the same problem or can replicate it on this or a similar version of sqlite do reopen it.

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