Skip to content

fix(serializers): keep strings that only start with a date as strings - #1353

Open
RaphaelFakhri wants to merge 7 commits into
dapr:mainfrom
RaphaelFakhri:fix/json-decoder-date-prefix
Open

RaphaelFakhri wants to merge 7 commits into
dapr:mainfrom
RaphaelFakhri:fix/json-decoder-date-prefix

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Description

DaprJSONDecoder.custom_scanstring sends every string whose prefix matches \d{4}[-/]\d{2}[-/]\d{2} to dateutil.parser.parse. When the rest of the string is not part of a date, as in '2024-01-01 meeting notes', the parser raises ParserError and the whole deserialization fails. This breaks reading actor state and actor method payloads that contain such strings.

This change catches ValueError (the base class of ParserError) and OverflowError from the parser and returns the original string. Strings that parse as dates still decode to datetime, so existing behavior doesn't change for them.

Issue reference

Fixes #1352

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
@RaphaelFakhri
RaphaelFakhri requested review from a team as code owners November 5, 2026 06:36
@CasperGN CasperGN self-assigned this Nov 5, 2026
@acroca
acroca requested a balanced review from Copilot November 5, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change that preserves date-prefixed strings when parsing fails.

No open issues 🎉

What changed in this PR

Fixes #1352 by preserving date-prefixed strings when date parsing fails, preventing deserialization errors in actor state and payloads while retaining existing datetime conversion behavior.

Changes:

  • Catch ValueError and OverflowError during date parsing and return the original string.
  • Add regression coverage for date-prefixed notes and filenames using hyphen and slash separators.
File Description
tests/​serializers/​test_default_json_serializer.py Verifies that date-prefixed text remains unchanged.
dapr/​serializers/​json.py Falls back to the original string when date parsing fails.

Review effort: Balanced

@sicoyle sicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

amazing - thank you for this great and very focused contribution!! you rock 🚀

@sicoyle sicoyle added automerge allows dapr bot to merge a PR after tests pass autoupdate labels Nov 6, 2026
@dapr-bot
dapr-bot enabled auto-merge November 6, 2026 15:11
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.73%. Comparing base (3358174) to head (5327934).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1353   +/-   ##
=======================================
  Coverage   88.72%   88.73%           
=======================================
  Files         166      166           
  Lines       13632    13635    +3     
=======================================
+ Hits        12095    12099    +4     
+ Misses       1537     1536    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge allows dapr bot to merge a PR after tests pass autoupdate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DefaultJSONSerializer raises ParserError on strings that start with a date

5 participants