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

DateParserPlugin doesn't set default for basedate #50

Open
CodeOptimist opened this issue Dec 5, 2023 · 0 comments
Open

DateParserPlugin doesn't set default for basedate #50

CodeOptimist opened this issue Dec 5, 2023 · 0 comments

Comments

@CodeOptimist
Copy link

CodeOptimist commented Dec 5, 2023

Although DateParserPlugin.__init__ states:

        :param basedate: a datetime object representing the current time
            against which to measure relative dates. If you do not supply this
            argument, the plugin uses ``datetime.utcnow()``.

and is likely referring to both ParserBase.date_from() and DateParse.date_from() that assume a default of datetime.utcnow() when their own basedate parameter is None, other functions called within DateParserPlugin, like whoosh.util.times.timespan.disambiguated() require a non-None value.

As such, submitting a date range query like [oct 1970 to dec 8 19z70] (intentional typo), throws:

  File "...\whoosh\util\times.py", line 334, in disambiguated
    end.year = max(start.year, basedate.year)
                               ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'year'

Proposed fix

I may have missed something, but as both date_from() are only called within dateparse.py from what I can tell, it might make sense to remove

        if basedate is None:
            basedate = datetime.utcnow()

and =None parameter defaults and simply set within DateParserPlugin.__init__ as follows?

        self.basedate = basedate or datetime.utcnow()

Collecting these issues for now, will fix in a fork eventually.

@CodeOptimist CodeOptimist changed the title DateParserPlugin doesn't set default for basedate DateParserPlugin doesn't set default for basedate Dec 5, 2023
cclauss pushed a commit to cclauss/whoosh-1 that referenced this issue Feb 9, 2024
https://packaging.python.org/en/latest/discussions/pip-vs-easy-install/#pip-vs-easy-install

# Description

Please include:
* relevant motivation
* a summary of the change
* which issue is fixed.
* any additional dependencies that are required for this change.

Closes: # (issue)

# Checklist:

- [x] I have performed a self-review of my own code
- [ ] I have commented my code in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant