Skip to content

fix: string-to-datetime prep transform fails on timestamps without seconds - #262

Open
iabaako wants to merge 1 commit into
fix/253-standardize-reapply-error-handlingfrom
fix/261-datetime-parse-crash
Open

fix: string-to-datetime prep transform fails on timestamps without seconds#262
iabaako wants to merge 1 commit into
fix/253-standardize-reapply-error-handlingfrom
fix/261-datetime-parse-crash

Conversation

@iabaako

@iabaako iabaako commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Pull Request Summary 🚀

What does this PR do? 📝

Fixes #261: converting a string column to datetime via a Prep step crashed the whole Streamlit app with an uncaught traceback whenever the value's time component had no seconds (e.g. 3/15/2026 17:28).

  • Adds no-seconds (H:MM/HH:MM) format variants alongside every existing date+time shape in _parse_flexible_datetime (ISO, Stata-style 18aug2025, M/D/Y, D/M/Y), so timestamps missing seconds now parse correctly.
  • Wraps the interactive "Add Prep Step" apply call (prep_add_stepprep_apply_action) in try/except (ValidationError, OperationError) with st.error(...), matching the pattern already used by the correction view's interactive apply, so a still-unsupported format now shows a friendly error instead of crashing the whole app.

Why is this change needed? 🤔

Timestamps without seconds are a common real-world shape (spreadsheet/Excel exports, some submissiondate-like fields), and every format _parse_flexible_datetime tried required HH:MM:SS. On top of the parsing gap, the interactive prep-apply path had no error boundary, so any parse failure took down the whole app with a raw traceback rather than a usable message.

How was this implemented? 🛠️

  • processing/prep.py: added a %H:%M-only validator/format pair immediately after each existing %H:%M:%S entry in TransformColumnsOperation._parse_flexible_datetime's formats_to_try list. The no-seconds validators are anchored ($) so they can't accidentally match a with-seconds value.
  • views/prep_view.py: wrapped prep_apply_action(project_id, label, PrepActionResult(**prep_args)) in prep_add_step's Add-button handler in try/except, showing st.error(f"Error adding preparation step: {e!s}") on failure and only calling st.success/st.rerun on success.

How to test or reproduce? 🧪

  1. uv run python -m pytest — full suite passes.
  2. just lint-py / just fmt-python / pre-commit — clean.
  3. Manual: add a "string to datetime" prep step on a column containing 3/15/2026 17:28 — it now converts successfully instead of crashing the app.
  4. Manual: add a "string to datetime" prep step on a column with a genuinely unsupported format — the page now shows a red error message instead of an uncaught traceback.

Screenshots (if applicable) 📷

N/A — bug fix, no new visual components.

Checklist ✅

  • I have run and tested my changes locally
  • I have limit this PR to less than 1000 lines of code change (if not, explain why)
  • I have updated/added tests to cover my changes (if applicable)
  • I have updated/added requirements to cover my changes (if applicable) — N/A, no new dependencies
  • I have run linting and formatting on any code changes (if applicable)
  • I have updated the documentation (README, etc.) accordingly — N/A, no user-facing docs changes needed
  • I have reviewed and resolved any merge conflict

Note on stacking

This PR is stacked on fix/253-standardize-reapply-error-handling (#260), which is still an open draft. Base is set to that branch rather than main so review only shows this PR's incremental diff; once #260 merges, retarget this PR's base to main.

🤖 Generated with Claude Code

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@iabaako
iabaako marked this pull request as ready for review August 7, 2026 10:41
@iabaako
iabaako requested a review from a team as a code owner August 7, 2026 10:41
self, mock_prep_apply, sample_polars_df
):
"""A failing transform shows st.error instead of crashing the app."""
import datasure.views.prep_view as pv
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.

String-to-datetime prep action crashes the app on timestamps without seconds (e.g. "3/15/2026 17:28")

1 participant