Skip to content

fix: convert published_date str to datetime in zenodo and hal connectors - #62

Open
dli1986 wants to merge 1 commit into
openags:mainfrom
dli1986:fix/zenodo-hal-published-date-isoformat
Open

fix: convert published_date str to datetime in zenodo and hal connectors#62
dli1986 wants to merge 1 commit into
openags:mainfrom
dli1986:fix/zenodo-hal-published-date-isoformat

Conversation

@dli1986

@dli1986 dli1986 commented Apr 24, 2026

Copy link
Copy Markdown

Bug: search_zenodo and search_hal raise 'str' object has no attribute 'isoformat' when results are returned via search_papers(sources="all").

Root cause: Both connectors assign a plain string to Paper.published_date, but Paper.to_dict() calls .isoformat() on it, which only works on datetime objects.

Fix: Import datetime in both files and parse the date string into a datetime object before constructing Paper(). Falls back to year-only or None if parsing fails.
error message:
"errors": {
"zenodo": "'str' object has no attribute 'isoformat'",
"hal": "'str' object has no attribute 'isoformat'"
},

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_date strings into datetime (with year-only fallback).
  • Parse HAL publication/submission dates into datetime, and pass datetime (not str) into Paper(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,
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

Successfully merging this pull request may close these issues.

3 participants