You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When updating an index through Eve with mongo_indexes, if the keys in the index changes after the index was already created, pymongo will throw an exception instead of Eve dropping the existing index and recreating it as claimed.
Also remember that, by default, any already existent index for which the definition has been changed, will be dropped and re-created
In my settings.py
DOMAIN= {
'users': {
'schema': {'username': {'type': 'string'}, 'token': {'type': 'string'}},
'mongo_indexes': {'my_index': [('username', 1)]}
}
}
# Run the app, the collection with the index gets created fine
# Later, we change the index here toDOMAIN= {
'users': {
'schema': {'username': {'type': 'string'}, 'token': {'type': 'string'}},
'mongo_indexes': {'my_index': [('username', 1), ('token', 1)]}
}
}
# And run the app again
Actual Behavior
The existing index does not get dropped and recreated. Instead, pymongo throws an exception since it attempts to create another index with the same name but different keys
Traceback (most recent call last):
File "run.py", line 2, in <module>
app = Eve()
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/eve/flaskapp.py", line 178, in __init__self.register_resource(resource, settings)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/eve/flaskapp.py", line 932, in register_resource
ensure_mongo_indexes(self, resource)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/eve/io/mongo/mongo.py", line 969, in ensure_mongo_indexes
_create_index(app, resource, name, list_of_keys, index_options)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/eve/io/mongo/mongo.py", line 1020, in _create_index
coll.create_index(list_of_keys, **kw)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/collection.py", line 1754, in create_indexself.__create_index(keys, kwargs, session, **cmd_options)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/collection.py", line 1656, in __create_index
session=session)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/collection.py", line 245, in _command
retryable_write=retryable_write)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/pool.py", line 517, in command
collation=collation)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/network.py", line 125, in command
parse_write_concern_error=parse_write_concern_error)
File "/home/dev/envs/medscan3.6/lib/python3.5/site-packages/pymongo/helpers.py", line 145, in _check_command_responseraise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: Index must have unique name.The existing index: { v: 2, key: { username: 1 }, name: "my_index", ns: "eve.users" } has the same name as the requested index: { v: 2, key: { username: 1, token: 1 }, name: "my_index", ns: "eve.users" }
A quick test shows the exception I receive has an error code of 86, which according to mongo's source represents IndexKeySpecsConflict (85 is IndexOptionsConflict)
When updating an index through Eve with
mongo_indexes
, if the keys in the index changes after the index was already created, pymongo will throw an exception instead of Eve dropping the existing index and recreating it as claimed.Expected Behavior
From http://python-eve.org/config.html
In my
settings.py
Actual Behavior
The existing index does not get dropped and recreated. Instead, pymongo throws an exception since it attempts to create another index with the same name but different keys
Additional Info
I believe this is because the code Eve uses to recreate the index expects an error code from pymongo to be 85
https://github.com/pyeve/eve/blob/master/eve/io/mongo/mongo.py#L1059
A quick test shows the exception I receive has an error code of 86, which according to mongo's source represents
IndexKeySpecsConflict
(85 isIndexOptionsConflict
)https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err#L87
Environment
The text was updated successfully, but these errors were encountered: