Opened 11 years ago

Closed 11 years ago

#616 closed defect (fixed)

Deleting user account crashes if you have attachements on your media

Reported by: joar Owned by: Elrond
Priority: critical Milestone: 0.3.3
Component: programming Keywords: sql
Cc: Elrond, joar Parent Tickets:

Description

File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/exceptions/errormiddleware.py', line 144 in __call__
  app_iter = self.application(environ, sr_checker)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/urlmap.py', line 203 in __call__
  return app(environ, start_response)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/Beaker-1.6.3-py2.7.egg/beaker/middleware.py', line 155 in __call__
  return self.wrap_app(environ, session_start_response)
File '/home/joar/git/mediagoblin/mediagoblin/app.py', line 236 in __call__
  return self.call_backend(environ, start_response)
File '/home/joar/git/mediagoblin/mediagoblin/app.py', line 216 in call_backend
  response = controller(request)
File '/home/joar/git/mediagoblin/mediagoblin/decorators.py', line 48 in new_controller_func
  return controller(request, *args, **kwargs)
File '/home/joar/git/mediagoblin/mediagoblin/edit/views.py', line 277 in delete_account
  request.user.delete()
File '/home/joar/git/mediagoblin/mediagoblin/db/models.py', line 93 in delete
  media.delete(del_orphan_tags=False, commit=False)
File '/home/joar/git/mediagoblin/mediagoblin/db/models.py', line 251 in delete
  for comment in self.get_comments():
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/query.py', line 2226 in __iter__
  self.session._autoflush()
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/session.py', line 1012 in _autoflush
  self.flush()
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/session.py', line 1583 in flush
  self._flush(objects)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/session.py', line 1654 in _flush
  flush_context.execute()
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/unitofwork.py', line 331 in execute
  rec.execute(self)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/unitofwork.py', line 475 in execute
  uow
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/persistence.py', line 59 in save_obj
  mapper, table, update)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/orm/persistence.py', line 485 in _emit_update_statements
  execute(statement, params)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/engine/base.py', line 1449 in execute
  params)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/engine/base.py', line 1584 in _execute_clauseelement
  compiled_sql, distilled_params
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/engine/base.py', line 1698 in _execute_context
  context)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/engine/base.py', line 1691 in _execute_context
  context)
File '/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/SQLAlchemy-0.7.8-py2.7.egg/sqlalchemy/engine/default.py', line 331 in do_execute
  cursor.execute(statement, parameters)
IntegrityError: (IntegrityError) core__attachment_files.media_entry may not be NULL u'UPDATE core__attachment_files SET media_entry=? WHERE core__attachment_files.id = ?' (None, 2)

Change History (4)

comment:1 by Christopher Allan Webber, 11 years ago

So, I think there's some question about how we handle cascading deletes. This is both an issue for MediaEntries, and it's an issue for here.

Assuming we do the .delete() of a user, what about the other things that need to happen for each of their media entries? That is to say, deleting each of their media entries' files as well.

What I think is we probably need to do this: Deleting a user sets up a celery task with a series of subtasks for each media deletion. This way there isn't an http timeout as a bunch of files are potentially deleted from disk (which would be totally wonky)

So, this wouldn't be relying on the de-facto cascading delete code of sqlalchemy. (Also, I'll note that cascading deletes are just going to get more and more complex as we go the way of the plugin..)

comment:2 by Christopher Allan Webber, 11 years ago

Cc: Elrond joar added

comment:3 by Elrond, 11 years ago

Owner: set to Elrond
Status: newaccepted

Okay, because I wanted to reproduce another error that joar found, I wrote a unit test and then fixed both. It's in a local tree, just wanted to take the bug, so that nobody else needs to invest time.

News at 10.

comment:4 by Elrond, 11 years ago

Resolution: fixed
Status: acceptedclosed

Should be fixed with df5b142ab9bfc590f17768079104f6cfa2cd7bba.

Note: See TracTickets for help on using tickets.