-
Notifications
You must be signed in to change notification settings - Fork 359
Fix: Reinstate dateparser==1.2.2 with a workaround for the upstream issue #5076
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| UPSTREAM_PICKLE_FILE_SIGNATURES = { | ||
| "a3a8d27b822072fa5c67c0651cb3c934" # distributed with dateparser==1.2.2 | ||
| } | ||
|
|
||
|
|
||
| def fix_dateparser() -> None: | ||
| # work around the following upstream issues in dateparser==1.2.2 (which all have the same root cause): | ||
| # - https://github.com/scrapinghub/dateparser/issues/1270 | ||
| # - https://github.com/scrapinghub/dateparser/issues/1281 | ||
| # - https://github.com/scrapinghub/dateparser/issues/1282 | ||
| # | ||
| # This hack can be removed if this issue is fixed upstream. | ||
| # If you're removing this hack, make sure to update pyproject.toml to blacklist version 1.2.2 | ||
|
|
||
| import importlib, hashlib | ||
| from pathlib import Path | ||
|
|
||
| tz_cache = None | ||
| spec = importlib.util.find_spec("dateparser") | ||
| if spec and spec.origin: | ||
| # spec.origin will be something like: | ||
| # "/path/to/venv/lib/python3.9/site-packages/dateparser/__init__.py" | ||
| tz_cache = Path(spec.origin).parent / "data" / "dateparser_tz_cache.pkl" | ||
| if tz_cache.exists(): | ||
| # if the tz_cache file matches the signature of the buggy upstream one, delete it | ||
| # deleting it forces it to be correctly re-generated for the local environment when dateparser is imported | ||
| signature = hashlib.md5(tz_cache.read_bytes()).hexdigest() | ||
| if signature in UPSTREAM_PICKLE_FILE_SIGNATURES: | ||
| try: | ||
| tz_cache.unlink() | ||
| except Exception as e: | ||
| print(f"WARNING: Unable to delete upstream dateparser cache: {str(e)}") | ||
|
|
||
| # Test that it actually worked | ||
| import dateparser | ||
|
|
||
| if dateparser.parse("1 minute ago") is None: | ||
| hint_filename = ( | ||
| str(tz_cache) | ||
| if tz_cache is not None | ||
| else "site-packages/dateparser/data/dateparser_tz_cache.pkl" | ||
| ) | ||
| print( | ||
| "WARNING: Buggy dateparser detected; some date expressions may fail to parse.\n" | ||
| f"Please either delete the file '{hint_filename}' manually or use dateparser<=1.2.1" | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pin forces SQLMesh to use the version of dateparser that contains the performance enhancements (which dont exist in any other version), but also the parsing regression that this PR provides a workaround for