Skip to content

Fix Memgraph parameter serialization error for cited_by_count_date#42

Merged
ssheikholeslami merged 2 commits intomainfrom
fix/memgraph-serialization
Jan 27, 2026
Merged

Fix Memgraph parameter serialization error for cited_by_count_date#42
ssheikholeslami merged 2 commits intomainfrom
fix/memgraph-serialization

Conversation

@ssheikholeslami
Copy link
Copy Markdown
Collaborator

Summary

  • Change cited_by_count_date type from Optional[datetime] to Optional[int] in AnonymousArticle model

Problem

When ingesting DOIs, the Article.save() query fails with:
Memgraph.ExecutionException - Couldn't read parameters!

The root cause is a type mismatch:

  • parser.py passes datetime.now().year which is an int (e.g. 2026)
  • The model declares cited_by_count_date: Optional[datetime]
  • Pydantic converts the int into a datetime object (interpreting it as a Unix timestamp)
  • The Neo4j driver serializes this as a Bolt temporal type
  • Memgraph cannot deserialize the temporal type parameter

Fix

Changed the type annotation in models.py to Optional[int], which matches the actual usage. The field only stores the year the citation count was fetched, not a full datetime.

Test plan

  • Run research_index list_of_dois.csv -l 5 — DOIs ingested without errors
  • Verify Memgraph logs show no Couldn't read parameters! errors
  • Run hatch test — all tests pass

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Memgraph parameter serialization failures by aligning the cited_by_count_date field type with actual usage (year integer) so the Neo4j driver doesn’t send a Bolt temporal parameter that Memgraph can’t deserialize.

Changes:

  • Change AnonymousArticle.cited_by_count_date from Optional[datetime] to Optional[int].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

openalex: Optional[str] = None
cited_by_count: Optional[int] = None
cited_by_count_date: Optional[datetime] = None
cited_by_count_date: Optional[int] = None
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

cited_by_count_date now stores a year integer rather than a full date/time, so the field name is misleading and can cause confusion for future readers/DB consumers. Consider renaming it to something like cited_by_count_year (and, if you need to keep the persisted property name stable, use a Pydantic alias or a clear field description).

Suggested change
cited_by_count_date: Optional[int] = None
cited_by_count_year: Optional[int] = Field(
default=None,
alias="cited_by_count_date",
description="Year associated with cited_by_count; persisted as 'cited_by_count_date'.",
)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@willu47 willu47 left a comment

Choose a reason for hiding this comment

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

Looks good @ssheikholeslami

I'd recommend changing the name as the CoPilot bot has recommended - cited_by_count_date should really be cited_by_count_year. However, this may have downstream effects on the research_index API and the memgraph database schema.

If you want to leave it for later, I suggest creating an issue and merging this as is.

@ssheikholeslami ssheikholeslami merged commit bfd46fb into main Jan 27, 2026
4 checks passed
@willu47 willu47 deleted the fix/memgraph-serialization branch January 27, 2026 15:05
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