burke-software / django-mass-edit

Make bulk changes in the Django admin interface
152 stars 67 forks source link

Uncaught error when edit creates duplicate entries #24

Closed gamesbook closed 9 years ago

gamesbook commented 10 years ago

If a user makes a changes that results in mass-edit creating one or more records that have duplicate entries, then an error is thrown that is not handled.

Is it possible that mass-edit can catch these and rather return a set of messages/warnings as to why the records in question were not altered?

File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
  17.             return view_func(request, *args, **kwargs)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/massadmin/massadmin.py" in mass_change_view
  65.     return ma.mass_change_view(request, object_ids)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/massadmin/massadmin.py" in mass_change_view
  183.                             self.save_model(request, new_object, form, change=True)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
  740.         obj.save()
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/models/base.py" in save
  546.                        force_update=force_update, update_fields=update_fields)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  626.                             rows = manager.using(using).filter(pk=pk_val)._update(values)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/models/query.py" in _update
  605.         return query.get_compiler(self.db).execute_sql(None)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1020.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  846.         cursor.execute(sql, params)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  41.             return self.cursor.execute(sql, params)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
  122.             six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
  120.             return self.cursor.execute(query, args)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/MySQLdb/cursors.py" in execute
  201.             self.errorhandler(self, exc, value)
File "/home/creation/.virtualenvs/s2s/local/lib/python2.7/site-packages/MySQLdb/connections.py" in defaulterrorhandler
  36.     raise errorclass, errorvalue

Exception Type: IntegrityError at /admin/myapp/site-masschange/120,121,124,122,123,365,371,377,383,389/
Exception Value: (1062, "Duplicate entry '5-1-1' for key 'site_id_2'")
bufke commented 10 years ago

This seems ideal. Error checking isn't so great on this project. I'd be happy to review any pull requests but I don't really have time to develop a fix right now.

It should probably start a database transaction, commit if successful, revert and show a message if unsuccessful.

gamesbook commented 9 years ago

we just installed version 2.2. The errors seem to be trapped now. The only remaining change would be, I think, to create a different error message for the case when the changes are NOT made successfully. At the moment, success and lack-of-success are both reported the same way.