fix(ops): db-aware health check + rate limit on paid API fan-out views - #379
Merged
Conversation
From the production-readiness audit:
- /health/ (Render's healthCheckPath) returned a static {"status": "ok"}
with no dependency check. A DB-down instance would still pass Render's
deploy gate. Now runs SELECT 1 and returns 503 if the DB is unreachable.
- No app-level rate limiting existed on views that fan out to paid,
metered third-party APIs (Rentometer, HUD FMR, ATTOM) via
screen_property() — a user re-screening a large pipeline, or repeating
screening_preview POSTs, had no cap on outbound calls. Added
core/decorators.py (rate_limit / is_rate_limited, built on
django.core.cache — no new dependency) and applied it to the three
views that trigger this fan-out: screening_preview (10/5min),
pipeline_screener's rescreen action (5/5min), and
pipeline_screening_settings' post-save rescreen (5/5min — criteria are
still saved even if the rescreen itself is rate-limited).
Also added an autouse cache-clearing fixture to the root conftest.py:
Django's cache is process-global, and without clearing it between tests,
rate-limit state (and Rentometer's own cache) leaks across test runs —
found this the hard way when a pre-existing screening-settings test
failed only when run after other tests that hit the same view.
Full suite: 2006 passed, 0 failures.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
| request, | ||
| "Too many re-screens — please wait a few minutes and try again.", | ||
| ) | ||
| return redirect(request.get_full_path()) |
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.
Summary
Two of the high-value fixes from the production-readiness audit:
/health/didn't verify anything — Render'shealthCheckPathgates deploys on this endpoint, but it returned a static{"status": "ok"}unconditionally. A DB-down instance would still pass the deploy gate. It now runsSELECT 1and returns503if the database is unreachable.screen_property()can call Rentometer/HUD FMR/ATTOM per property.screening_preview,pipeline_screener's rescreen action, andpipeline_screening_settings' post-save rescreen all iterate a user's entire pipeline with no cap on how often that can be triggered. Addedcore/decorators.py(rate_limit/is_rate_limited, built ondjango.core.cache— no new dependency) and applied it to all three.(The third audit item — rollback documentation — turned out to already exist in
docs/how-to-guides/render-deploy.md; no action needed there.)Changes
core/decorators.py(new) —rate_limit/is_rate_limitedcore/views/__init__.py— DB check inhealth_check; rate limiting on the three fan-out viewsconftest.py— autouse fixture clearing Django's cache between tests (found this was needed when a pre-existing test failed only when run after other tests hitting the same view — the cache is process-global)tests/test_rentometer.py— removed its now-redundant local cache-clearing fixture (superseded by the conftest one)core/tests/test_decorators.py,core/tests/test_views.py— new testsTest plan
ruff check/ruff format --check/mypycleanmanage.py check— no issues🤖 Generated with Claude Code