Bug 846031 - Adding a distributor to a repo via API causes duplicate Key Error
Adding a distributor to a repo via API causes duplicate Key Error
Status: CLOSED WORKSFORME
Product: Pulp
Classification: Community
Component: API/integration (Show other bugs)
2.0.6
Unspecified Unspecified
unspecified Severity unspecified
: ---
: Sprint 39
Assigned To: Jay Dobies
Preethi Thomas
: Triaged
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-08-06 11:14 EDT by Pradeep Kilambi
Modified: 2013-09-09 11:43 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-09-05 10:46:13 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Pradeep Kilambi 2012-08-06 11:14:23 EDT
Description of problem:

Adding a distributor to a repository via the api gives a duplicate key error

POST on /pulp/api/v2/repositories/<repoid>/distributors/

2012-08-06 10:46:34,575 12867:140591868974848: pulp.server.webservices.middleware.exception:ERROR: exception:63 Unhandled Exception
Traceback (most recent call last):
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/middleware/exception.py", line 44, in __call__
    return self.app(environ, start_response)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/middleware/postponed.py", line 38, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 279, in wsgi
    result = self.handle_with_processors()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 28, in _handle_with_processors
    return process(self.processors)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 558, in processor
    return handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 573, in processor
    result = handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 27, in process
    return self.handle()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 414, in _delegate
    return f()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 422, in <lambda>
    f = lambda: self._delegate_sub_application(pat, what)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 447, in _delegate_sub_application
    return app.handle_with_processors()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 28, in _handle_with_processors
    return process(self.processors)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 558, in processor
    return handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 573, in processor
    result = handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 27, in process
    return self.handle()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 233, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 412, in _delegate
    return handle_class(cls)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 387, in handle_class
    return tocall(*args)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/controllers/decorators.py", line 137, in _auth_decorator
    value = method(self, *args, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/controllers/repositories.py", line 584, in POST
    return execution.execute_created(self, call_request, distributor_id)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/dispatch/task.py", line 130, in _run
    result = call(*args, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/managers/repo/distributor.py", line 206, in add_distributor
    distributor_coll.save(distributor, safe=True)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/db/connection.py", line 80, in retry
    return method(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 237, in save
    manipulate, safe, _check_keys=True, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/db/connection.py", line 80, in retry
    return method(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 411, in update
    _check_keys, self.__uuid_subtype), safe)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 822, in _send_message
    return self.__check_response_to_last_error(response)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 770, in __check_response_to_last_error
    raise DuplicateKeyError(error["err"])
DuplicateKeyError: E11000 duplicate key error index: pulp_database.repo_distributors.$repo_id_-1_id_-1  dup key: { : "testrepo", : "iso_distributor" }
Comment 1 Jay Dobies 2012-09-05 10:46:13 EDT
I can't reproduce this. I set up a script to create a repo and add both an ISO and yum distributor and it worked. Without more details on the call you made, this is going to be hard to debug. If this is an issue, we'll run into it when we start using the ISO distributor for normal repositories. For now, I'm closing this out figuring it was a local environment issue during dev.

Below are the REST calls back and forth for adding the two distributors. I even made the call to add the iso distributor twice; the first is replaced by the second and no duplicate was seen. No error was received:

Request Body
{
  "distributor_id": "yum_distributor", 
  "distributor_type_id": "yum_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true, 
    "relative_url": "http://localhost"
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "yum_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "504765028a905b04e9000094"
  }, 
  "config": {
    "http": true, 
    "relative_url": "http://localhost", 
    "https": true
  }, 
  "id": "yum_distributor"
}
Request Body
{
  "distributor_id": "iso_distributor", 
  "distributor_type_id": "iso_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "iso_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "504765028a905b04e900009a"
  }, 
  "config": {
    "http": true, 
    "https": true
  }, 
  "id": "iso_distributor"
}
Request Body
{
  "distributor_id": "iso_distributor", 
  "distributor_type_id": "iso_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "iso_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "5047656b8a905b04e90000b7"
  }, 
  "config": {
    "http": true, 
    "https": true
  }, 
  "id": "iso_distributor"
}

Note You need to log in before you can comment on or make changes to this bug.