POST to /images setting x-image-meta-id to an already existing image id causes a 500 error

Bug #813291 reported by Justin Shepherd
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Low
Justin Shepherd

Bug Description

I have created a test in tests/functional/test_httplib2_api.py to show the steps to reproduce the issue:

test_duplicate_image_upload()

=====

The following traceback gets returned as the content from the POST:

Traceback (most recent call last):
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/eventlet/wsgi.py", line 336, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 147, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 208, in call_func
    return self.func(req, *args, **kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/wsgi.py", line 113, in __call__
    response = req.get_response(self.application)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/request.py", line 1053, in get_response
    application, catch_exc_info=False)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/request.py", line 1022, in call_application
    app_iter = application(self.environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
    return resp(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/routes/middleware.py", line 131, in __call__
    response = self.app(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
    return resp(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 147, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 208, in call_func
    return self.func(req, *args, **kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/wsgi.py", line 311, in __call__
    request, **action_args)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/wsgi.py", line 328, in dispatch
    return method(*args, **kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/api/v1/images.py", line 407, in create
    image_meta = self._reserve(req, image_meta)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/api/v1/images.py", line 229, in _reserve
    image_meta)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/__init__.py", line 56, in add_image_metadata
    new_image_meta = c.add_image(image_meta)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/client.py", line 96, in add_image
    res = self.do_request("POST", "/images", body, headers=headers)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/client.py", line 142, in do_request
    raise Exception("Internal Server error: %s" % res.read())
Exception: Internal Server error: Traceback (most recent call last):
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/eventlet/wsgi.py", line 336, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
    return resp(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/routes/middleware.py", line 131, in __call__
    response = self.app(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
    return resp(environ, start_response)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 147, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 208, in call_func
    return self.func(req, *args, **kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/wsgi.py", line 311, in __call__
    request, **action_args)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/common/wsgi.py", line 328, in dispatch
    return method(*args, **kwargs)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/server.py", line 265, in create
    image_data = db_api.image_create(context, image_data)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/db/api.py", line 95, in image_create
    return _image_update(context, values, None, False)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/db/api.py", line 276, in _image_update
    image_ref.save(session=session)
  File "/Users/justinshepherd/Projects/bzr/glance/duplicate_image_upload/glance/registry/db/models.py", line 55, in save
    session.flush()
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/orm/session.py", line 1400, in flush
    self._flush(objects)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/orm/session.py", line 1481, in _flush
    flush_context.execute()
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/orm/unitofwork.py", line 302, in execute
    rec.execute(self)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/orm/unitofwork.py", line 446, in execute
    uow
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/orm/mapper.py", line 1887, in _save_obj
    execute(statement, params)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1191, in execute
    params)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1271, in _execute_clauseelement
    return self.__execute_context(context)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1302, in __execute_context
    context.parameters[0], context=context)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1401, in _cursor_execute
    context)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1394, in _cursor_execute
    context)
  File "/Users/justinshepherd/Projects/bzr/glance/lp803656/.glance-venv/lib/python2.6/site-packages/sqlalchemy/engine/default.py", line 299, in do_execute
    cursor.execute(statement, parameters)
IntegrityError: (IntegrityError) PRIMARY KEY must be unique u'INSERT INTO images (created_at, updated_at, deleted_at, deleted, id, name, disk_format, container_format, size, status, is_public, location, checksum) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ('2011-07-20 03:55:08.360742', None, None, 0, 1, u'Image1 Update', u'vdi', u'ovf', 19, u'queued', 1, None, None)

Related branches

Changed in glance:
status: New → In Progress
assignee: nobody → Justin Shepherd (jshepher)
Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → diablo-3
Jay Pipes (jaypipes)
Changed in glance:
importance: Undecided → Low
Thierry Carrez (ttx)
Changed in glance:
milestone: diablo-3 → 2011.3
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.