FIX: replace strptime with fromisoformat for date parsing - #785
FIX: replace strptime with fromisoformat for date parsing#785Lakshay Chauhan (nos1dot618) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Preserve previously supported input formats and add direct helper coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Replaces strptime() with fromisoformat() APIs for cursor date, datetime, and time parsing.
Changes:
- Updates the three parsing helpers.
- Adds no direct regression tests.
File summaries
| File | Findings |
|---|---|
mssql_python/cursor.py |
Moderate: New parsing rejects previously accepted non-zero-padded inputs; preserve compatibility and add regression coverage. Nit: Add direct tests for all three helpers, including prior valid and near-miss inputs. |
Review details
Suppressed comments (2)
mssql_python/cursor.py:466
datetime.fromisoformat()does not accept all inputs accepted by the removed format loop:strptimepermits non-zero-padded fields, so values such as2024-5-2 1:2:3previously parsed but now returnNone. Please preserve those legacy inputs by normalizing the fields or using a compatibility fallback, and cover the case with a regression test.
return datetime.datetime.fromisoformat(param)
mssql_python/cursor.py:481
time.fromisoformat()is stricter than the previousstrptimeformats:%H,%M, and%Saccepted non-zero-padded fields such as1:2:3, whereas this implementation returnsNone. That is a compatibility regression; normalize the legacy form before callingfromisoformat()(or retain a fallback) and add a regression case.
return datetime.time.fromisoformat(param)
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| continue | ||
| return None | ||
| try: | ||
| return datetime.date.fromisoformat(param) |
|
|
||
| return None # If all formats fail, return None | ||
| try: | ||
| return datetime.datetime.fromisoformat(param) |
|
After some digging, I found that Since this changes previously supported behavior and the goal is to maintain compatibility, I think it would be better to retain the existing functionality by normalizing the components before calling |
Work Item / Issue Reference
Summary
Replace
datetime.strptime()with the correspondingfromisoformat()APIs for date, datetime, and time parsing inCursor. This removes the RuffDTZ007warnings caused by constructing naive datetimes withstrptime()while preserving the existing parsing behavior. The existing cursor tests already cover date, datetime, and time parsing, so no new tests are required.