Skip to content

Commit 815bf72

Browse files
authored
Fix: uid in options does not overwrite the parameter in create_index (#105)
1 parent 653699e commit 815bf72

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

meilisearch/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def create(config, uid, options=None):
105105
"""
106106
if options is None:
107107
options = {}
108-
payload = {'uid': uid, **options}
108+
payload = {**options, 'uid': uid}
109109
return HttpRequests(config).post(config.paths.index, payload)
110110

111111
@staticmethod

meilisearch/tests/index/test_index.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class TestIndex:
99
client = meilisearch.Client(BASE_URL, MASTER_KEY)
1010
index_uid = 'indexUID'
1111
index_uid2 = 'indexUID2'
12+
index_uid3 = 'indexUID3'
1213

1314
def setup_class(self):
1415
clear_all_indexes(self.client)
@@ -27,11 +28,22 @@ def test_create_index_with_primary_key(self):
2728
assert index.uid == self.index_uid2
2829
assert index.get_primary_key() == 'book_id'
2930

31+
def test_create_index_with_uid_in_options(self):
32+
"""Tests creating an index with a primary key"""
33+
index = self.client.create_index(uid=self.index_uid3, options={'uid': 'wrong', 'primaryKey': 'book_id'})
34+
assert isinstance(index, object)
35+
assert index.uid == self.index_uid3
36+
assert index.get_primary_key() == 'book_id'
37+
3038
def test_get_indexes(self):
3139
"""Tests getting all indexes"""
3240
response = self.client.get_indexes()
41+
uids = [index['uid'] for index in response]
3342
assert isinstance(response, list)
34-
assert response[0]['uid'] == self.index_uid
43+
assert self.index_uid in uids
44+
assert self.index_uid2 in uids
45+
assert self.index_uid3 in uids
46+
assert len(response) == 3
3547

3648
def test_get_index_with_uid(self):
3749
"""Tests getting one index with uid"""
@@ -84,3 +96,10 @@ def test_delete_index(self):
8496
assert response.status_code == 204
8597
with pytest.raises(Exception):
8698
self.client.get_index(uid=self.index_uid2).info()
99+
index = self.client.get_index(uid=self.index_uid3)
100+
response = index.delete()
101+
assert isinstance(response, object)
102+
assert response.status_code == 204
103+
with pytest.raises(Exception):
104+
self.client.get_index(uid=self.index_uid3).info()
105+
assert len(self.client.get_indexes()) == 0

0 commit comments

Comments
 (0)