Skip to content

refactor(crm): route classes live in shared/routes.py for any api.py - #1459

Merged
manas-narra merged 1 commit into
juspay:crmfrom
Rahul-2903-juspay:refactor/crm-shared-route-classes
Nov 3, 2026
Merged

manas-narra merged 1 commit into
juspay:crmfrom
Rahul-2903-juspay:refactor/crm-shared-route-classes

Conversation

@Rahul-2903-juspay

Copy link
Copy Markdown
Contributor

Why

The two route classes that give a router a guarantee every route on it inherits lived inside the module that first needed them:

  • TranslatingRoute, which turns exceptions into status codes, was in connectivity/api.py;
  • BoundedBodyRoute, which caps the body before parsing and auth, was in record/api.py.

Another module could only get the same guarantees by copying the class. Module-to-module imports are off-limits, and the CRM root holds only api.py and auth.py, so the shared home is app/crm/shared/, which every module may import.

What changed

  • New app/crm/shared/routes.py with the generic pieces:
    • TranslatingRoute: a module overrides translate(error) and returns an HTTPException, or None to let the error pass through.
    • BoundedBodyRoute: a module overrides max_body_bytes(). It's read on every request, not fixed when the route is declared.
    • read_bounded(request, max_bytes): now takes the cap as an argument.
    • A subclass that doesn't define its policy raises TypeError when its first route is declared, at import, not on its first request.
  • connectivity: ConnectorsRoute(TranslatingRoute) passes on the module's existing translate table, which is unchanged.
  • record: IngestRoute(BoundedBodyRoute) returns MAX_LETTER_BYTES. The webhook bays call read_bounded(request, MAX_LETTER_BYTES), so it's still one cap across every ingest door.
  • Docs: building-modules.md says where the bases live and how to subclass them. CLAUDE.md lists shared/routes.py. The comment in static.py points at read_bounded's new home.

Behaviour

No change:

  • Connectors routes return the same 404, 409, 422 and 400.
  • The ingest doors return the same 413 over the cap and the same 400 when a client hangs up mid-body.
  • CRM_INGEST_MAX_BODY_BYTES still sets the cap.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bef0aca9-0710-4b96-bab0-b3e8ce564599

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@Rahul-2903-juspay
Rahul-2903-juspay force-pushed the refactor/crm-shared-route-classes branch from 8cf5e74 to 88e2f97 Compare November 3, 2026 12:15
@manas-narra

Copy link
Copy Markdown
Collaborator

Looks good: the refactor is clean and nothing breaks. One small fix before Swaroop looks.

🟡 app/crm/shared/routes/__init__.py re-exports its own files

from app.crm.shared.routes.classes import BoundedBodyRoute, TranslatingRoute
from app.crm.shared.routes.utils import read_bounded

Our module rules list this as a known mistake. docs/crm/building-modules.md:206 says: "Re-export hub __init__.py — import by full path." Swaroop removed the same pattern from outreach/nodes/__init__.py in #1101.

Fix (simplest): go back to the single file app/crm/shared/routes.py from your first push (8cf5e742). It's only 112 lines, so it doesn't need a folder. The imports in connectivity/api.py and record/api.py stay exactly as they are.

(Or keep the folder: leave __init__.py empty and import by full path, e.g. from app.crm.shared.routes.classes import TranslatingRoute.)


What I checked on 88e2f97f:

  • The crm branch's own tests, unchanged, pass on your code: 1784, the same as on crm.
  • tests/crm + tests/egress with your new tests: 1788 passed.
  • All 43 /crm routes keep the same route class as before.
  • It also passes on FastAPI 0.136, the fix: package-vulnerablities #1446 upgrade.
  • 17/17 mutations on the moved code are caught by tests.

@Rahul-2903-juspay
Rahul-2903-juspay force-pushed the refactor/crm-shared-route-classes branch from 88e2f97 to 6ffec99 Compare November 3, 2026 12:30
@manas-narra
manas-narra merged commit e7796e5 into juspay:crm Nov 3, 2026
3 checks passed
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.

2 participants