Skip to content
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

fix: make check_date_operators work with dateutil < 2.8.1 #273

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
15 changes: 12 additions & 3 deletions UnleashClient/constraints/Constraint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=invalid-name, too-few-public-methods, use-a-generator
from datetime import datetime
from enum import Enum
from typing import Optional, Union
from typing import Any, Optional, Union

import semver
from dateutil.parser import ParserError, parse
from dateutil.parser import parse

from UnleashClient.utils import LOGGER, get_identifier

Expand Down Expand Up @@ -123,13 +123,22 @@ def check_date_operators(self, context_value: Union[datetime, str]) -> bool:
return_value = False
parsing_exception = False

DateUtilParserError: Any

try:
from dateutil.parser import ParserError

DateUtilParserError = ParserError
except ImportError:
DateUtilParserError = ValueError

try:
parsed_date = parse(self.value)
if isinstance(context_value, str):
context_date = parse(context_value)
else:
context_date = context_value
except ParserError:
except DateUtilParserError:
LOGGER.error(f"Unable to parse date: {self.value}")
parsing_exception = True

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_create_feature_exception(test_feature):

def test_select_variation_novariation(test_feature):
selected_variant = test_feature.get_variant()
assert type(selected_variant) == dict
assert isinstance(selected_variant, dict)
assert selected_variant["name"] == "disabled"


Expand Down
Loading