fix: return unrecognized date strings unchanged in datefmt#859
Merged
Conversation
dgunning
approved these changes
Jun 14, 2026
dgunning
left a comment
Owner
There was a problem hiding this comment.
Approving — real crash, correct minimal fix. Thanks @gaoflow.
Reproduced the AttributeError: 'str' object has no attribute 'strftime' on main for all five inputs (2022/03/04, 2022-3-4, March 4, 2022, N/A, ""). Returning the unrecognized string unchanged is the right graceful-degradation behavior for a display-only helper called in 14 header/former-name render sites.
Verified on the branch (with a working-tree import): pass-through strings return unchanged with no crash, and recognized formats (20220304, 2022-03-04) still format correctly. All 9 TestDatefmt cases pass; the 5 pass-through cases fail on main.
dgunning
added a commit
that referenced
this pull request
Jun 15, 2026
datefmt() is display-only and called in 14 filing-header / former-name render sites with values that aren't guaranteed to be set — e.g. a former name's null `to` date (SEC `formerNames` JSON can carry `"to": null`) or a missing `date_of_change`. The non-string branch called `value.strftime` unconditionally, so `None` (or any unexpected type) raised `AttributeError` and took down the entire table render rather than just that field. Now returns "" for None, formats date/datetime objects, and falls back to str(value) for anything else. Complements the unrecognized-string pass-through fix in #859 (orthogonal change to the non-string branch). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
datefmt() only parsed %Y%m%d, %Y%m%d%H%M%S and %Y-%m-%d strings; any other string (e.g. '2022/03/04', a non-zero-padded date, or '') fell through to str.strftime and raised AttributeError. Return the string unchanged for unrecognized formats so the display helper degrades gracefully instead of crashing filing-header rendering.
139956f to
83f702a
Compare
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.
What
datefmt()(edgar/display/formatting.py) crashes withAttributeError: 'str' object has no attribute 'strftime'whenever it is handed a date string that does not match one of its three hard-coded patterns (YYYYMMDD,YYYYMMDDHHMMSS,YYYY-MM-DD).The
if isinstance(value, str)branch only reassignsvalueto a parseddatetimewhen a regex matches; otherwisevaluestays astrand falls through tovalue.strftime(fmt).Why it matters
datefmtis display-only and is called in 14 places on filing-derived date strings that are not guaranteed to be in one of the three formats, including the 10-K / 10-Q / 40-F header tables (period_of_report,filing_date), entity former-name rows (former_name['from']/['to']), and SGML header rendering (date_of_change). A single oddly-formatted or empty date string there takes down the whole table render rather than just that field.Fix
Return the unrecognized string unchanged instead of calling
strftimeon it, so the helper degrades gracefully. This keeps the function silent-failure-free (it returns the value it was given, neverNone) while matching the "useful behavior, not a crash" principle for display code.Verification
TestDatefmtadded totests/test_to_context.py(the existing home of theedgar.display.formattingunit tests): the recognized formats anddatetimeobjects still format correctly, and the five previously-crashing strings (2022/03/04,2022-3-4,March 4, 2022,N/A, ``) now pass through unchanged. The five pass-through cases fail onmainand pass with this change. `hatch run test-fast` for the file is green; `ruff check` is clean on the changed lines.