fix: convert published_date str to datetime in zenodo and hal connectors - #62
Open
dli1986 wants to merge 1 commit into
Open
fix: convert published_date str to datetime in zenodo and hal connectors#62dli1986 wants to merge 1 commit into
dli1986 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a serialization bug where Paper.published_date was set to a string in the Zenodo and HAL connectors, causing .isoformat() failures when results are serialized (e.g., via search_papers(sources="all")).
Changes:
- Parse Zenodo
publication_datestrings intodatetime(with year-only fallback). - Parse HAL publication/submission dates into
datetime, and passdatetime(notstr) intoPaper(published_date=...).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
paper_search_mcp/academic_platforms/zenodo.py |
Adds datetime parsing for Zenodo publication dates before building Paper. |
paper_search_mcp/academic_platforms/hal.py |
Adds datetime parsing for HAL dates and changes published_date to pass a datetime into Paper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| pub_date = datetime.fromisoformat(pub_date_str[:10]) | ||
| except ValueError: | ||
| pub_date = datetime(int(pub_date_str[:4]), 1, 1) |
Comment on lines
+248
to
+254
| pub_date_str = meta.get("publication_date", "") | ||
| pub_date = None | ||
| if len(pub_date_str) >= 4: | ||
| try: | ||
| pub_date = datetime.fromisoformat(pub_date_str[:10]) | ||
| except ValueError: | ||
| pub_date = datetime(int(pub_date_str[:4]), 1, 1) |
Comment on lines
259
to
+263
| title=title, | ||
| authors=authors, | ||
| abstract=abstract.strip(), | ||
| doi=doi, | ||
| published_date=str(pub_date), | ||
| published_date=pub_date, |
Comment on lines
242
to
+263
| @@ -251,8 +259,8 @@ | |||
| title=title, | |||
| authors=authors, | |||
| abstract=abstract.strip(), | |||
| doi=doi, | |||
| published_date=str(pub_date), | |||
| published_date=pub_date, | |||
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug:
search_zenodoandsearch_halraise'str' object has no attribute 'isoformat'when results are returned viasearch_papers(sources="all").Root cause: Both connectors assign a plain string to
Paper.published_date, butPaper.to_dict()calls.isoformat()on it, which only works ondatetimeobjects.Fix: Import
datetimein both files and parse the date string into adatetimeobject before constructingPaper(). Falls back to year-only orNoneif parsing fails.error message:
"errors": {
"zenodo": "'str' object has no attribute 'isoformat'",
"hal": "'str' object has no attribute 'isoformat'"
},