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

Parse settings do not accept subclass types #1115

Closed
majikman111 opened this issue Jan 5, 2023 · 1 comment
Closed

Parse settings do not accept subclass types #1115

majikman111 opened this issue Jan 5, 2023 · 1 comment

Comments

@majikman111
Copy link

Using a settings dictionary when parsing a date results in an error if the provided object is a subclass of the type specified in the dateparser settings schema, such as when using a pendulum.DateTime object . So running

settings = {
    "RELATIVE_BASE": pendulum.now()
}

dateparser.parse("-15m", settings=settings)

will generate the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.8/site-packages/dateparser/conf.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/lib/python3.8/site-packages/dateparser/__init__.py", line 58, in parse
    parser = DateDataParser(languages=languages, locales=locales,
  File "/lib/python3.8/site-packages/dateparser/conf.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/lib/python3.8/site-packages/dateparser/date.py", line 387, in __init__
    check_settings(settings)
  File "/lib/python3.8/site-packages/dateparser/conf.py", line 244, in check_settings
    raise SettingValidationError(
dateparser.conf.SettingValidationError: "RELATIVE_BASE" must be "datetime", not "DateTime".

Even though a pendulum.DateTime is a subclass of a datetime object. The check at this line https://github.com/scrapinghub/dateparser/blob/master/dateparser/conf.py#L243
should call isinstance instead of directly checking type equality to ensure subclassed objects are allowed in settings definitions. This is a regression from previous versions where pendulum.DateTime objects were allowed.

@majikman111
Copy link
Author

Resolved by #1223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants