Skip to content

Change utcnow to now with time zone #754

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
May 11, 2023
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/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def generate_tenant_token(
raise ValueError("An uid is required and must comply to the uuid4 format.")
if not search_rules or search_rules == [""]:
raise ValueError("The search_rules field is mandatory and should be defined.")
if expires_at and expires_at < datetime.datetime.utcnow():
if expires_at and expires_at < datetime.datetime.now(tz=datetime.timezone.utc):
raise ValueError("The date expires_at should be in the future.")

# Standard JWT header for encryption with SHA256/HS256 algorithm
Expand Down
4 changes: 2 additions & 2 deletions tests/client/test_client_tenant_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_generate_tenant_token_with_expires_at(client, get_private_key, empty_in
"""Tests create a tenant token with search rules and expiration date."""
empty_index()
client = meilisearch.Client(BASE_URL, get_private_key.key)
tomorrow = datetime.datetime.utcnow() + datetime.timedelta(days=1)
tomorrow = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1)

token = client.generate_tenant_token(
api_key_uid=get_private_key.uid, search_rules=["*"], expires_at=tomorrow
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_generate_tenant_token_with_bad_expires_at(client, get_private_key):
"""Tests create a tenant token with a bad expires at."""
client = meilisearch.Client(BASE_URL, get_private_key.key)

yesterday = datetime.datetime.utcnow() + datetime.timedelta(days=-1)
yesterday = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=-1)

with pytest.raises(Exception):
client.generate_tenant_token(
Expand Down