Skip to content

Make key description optional #1067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meilisearch/models/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class _KeyBase(CamelBase):
uid: str
name: Optional[str] = None
description: str
description: Optional[str]
actions: List[str]
indexes: List[str]
expires_at: Optional[datetime] = None
Expand Down
9 changes: 9 additions & 0 deletions tests/client/test_client_key_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def test_create_keys_default(client, test_key_info):
assert key.indexes == test_key_info["indexes"]


def test_create_keys_without_desc(client, test_nondescript_key_info):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did confirm it breaks without the change in the non-test code.

"""Tests the creation of a key with no optional argument."""
key = client.create_key(test_nondescript_key_info)
print(key)

assert key.name == "keyWithoutDescription"
assert key.description is None


def test_create_keys_with_options(client, test_key_info):
"""Tests the creation of a key with arguments."""
key = client.create_key(
Expand Down
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ def test_key_info(client):
pass


@fixture(scope="function")
def test_nondescript_key_info(client):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is really necessary, I didn't just change the test_key_info since that seemed a bit intrusive.

The reason why test_key_info would not work is because it uses descriptions to identify the keys that it created, which of course is a problem if the descriptions are None.

I think it would probably be best to delete this function and update the original one to use created_at, or just use the fact that the most recently created key should be first:

NOTE
API keys are displayed in descending order based on their createdAt date. This means that the most recently created keys appear first.

https://www.meilisearch.com/docs/reference/api/keys#get-all-keys

key_info = {
"name": "keyWithoutDescription",
"actions": ["search"],
"indexes": [common.INDEX_UID],
"expiresAt": None,
}

yield key_info

try:
keys = client.get_keys().results
key = next(x for x in keys if x.name == key_info["name"])
client.delete_key(key.key)
except MeilisearchApiError:
pass
except StopIteration:
pass


@fixture(scope="function")
def get_private_key(client):
keys = client.get_keys().results
Expand Down
Loading