Repository navigation
fix(query): reject invalid date filters - #710
Conversation
Problem: storage filter pushdown converted invalid since/until values to epoch 0.0. That made malformed date filters behave like an extremely broad query instead of reporting bad input. What changed: make invalid date values raise ValueError with a clear format hint after ISO and numeric parsing both fail. Add storage filter coverage for since and until. Verification: ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; ruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; pytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQL Ref #621
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 12 minutes and 8 seconds.Comment |
Polylogue Proof PackRefs: Affected Domains
Focused Gates
Required PR Gates
Optional Confidence Gates
Known Gaps
Oracle / Cost
|
There was a problem hiding this comment.
Pull request overview
This PR tightens storage-level conversation date filtering by making malformed since/until values fail fast (rather than silently broadening queries by treating them as epoch zero), and adds unit tests to enforce the new behavior.
Changes:
- Update
_iso_to_epoch()to raiseValueErrorwhen both ISO and numeric parsing fail (instead of returning0.0). - Add unit tests asserting invalid
sinceand invaliduntilinputs raise.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
polylogue/storage/backends/queries/filter_builder.py |
Changes date parsing to raise on invalid since/until values instead of defaulting to epoch zero. |
tests/unit/storage/test_schema_safety.py |
Adds regression tests for invalid since/until date filter inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_build_filters_rejects_invalid_since_filter(self) -> None: | ||
| """Invalid date filters should not silently broaden to epoch zero.""" | ||
| from polylogue.storage.backends.queries.filter_builder import _build_conversation_filters | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid date filter value"): | ||
| _build_conversation_filters(since="not-a-date") | ||
|
|
||
| def test_build_filters_rejects_invalid_until_filter(self) -> None: | ||
| """Invalid date filters should not silently broaden to epoch zero.""" | ||
| from polylogue.storage.backends.queries.filter_builder import _build_conversation_filters | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid date filter value"): | ||
| _build_conversation_filters(until="not-a-date") |
| def _iso_to_epoch(iso_str: str) -> float: | ||
| """Convert an ISO date string to epoch seconds for SQL comparison.""" | ||
| from datetime import datetime | ||
|
|
||
| try: | ||
| return datetime.fromisoformat(iso_str).timestamp() | ||
| except (ValueError, TypeError): | ||
| try: | ||
| return float(iso_str) | ||
| except (ValueError, TypeError): | ||
| return 0.0 | ||
| pass | ||
| try: | ||
| return float(iso_str) | ||
| except (ValueError, TypeError): | ||
| raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None |
| try: | ||
| return float(iso_str) | ||
| except (ValueError, TypeError): | ||
| raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None |
| try: | ||
| return float(iso_str) | ||
| except (ValueError, TypeError): | ||
| raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None |
Summary: Make storage-level since/until filter pushdown reject malformed date values instead of silently treating them as epoch zero. Problem: The low-level conversation filter builder converted invalid date strings to 0.0. A malformed since/until value could therefore broaden to a near-unbounded query and look like a successful filter. Solution: After ISO and numeric parsing both fail, _iso_to_epoch() now raises ValueError with a format hint. Storage filter tests cover both since and until. Verification: ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; ruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; pytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQL; git push pre-push hook ran devtools verify --quick and passed. Ref #621
Summary
Make storage-level
since/untilfilter pushdown reject malformed date values instead of silently treating them as epoch zero.Problem
The low-level conversation filter builder converted invalid date strings to
0.0. A malformedsince/untilvalue could therefore broaden to a near-unbounded query and look like a successful filter.Solution
After ISO and numeric parsing both fail,
_iso_to_epoch()now raisesValueErrorwith a format hint. Storage filter tests cover bothsinceanduntil.Verification
ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.pyruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.pypytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQLgit pushpre-push hook:devtools verify --quickpassedRef #621