Repository navigation
refactor(crm): route classes live in shared/routes.py for any api.py - #1459
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
8cf5e74 to
88e2f97
Compare
|
Looks good: the refactor is clean and nothing breaks. One small fix before Swaroop looks. 🟡 from app.crm.shared.routes.classes import BoundedBodyRoute, TranslatingRoute
from app.crm.shared.routes.utils import read_boundedOur module rules list this as a known mistake. Fix (simplest): go back to the single file (Or keep the folder: leave What I checked on
|
88e2f97 to
6ffec99
Compare
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 inconnectivity/api.py;BoundedBodyRoute, which caps the body before parsing and auth, was inrecord/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.pyandauth.py, so the shared home isapp/crm/shared/, which every module may import.What changed
app/crm/shared/routes.pywith the generic pieces:TranslatingRoute: a module overridestranslate(error)and returns anHTTPException, orNoneto let the error pass through.BoundedBodyRoute: a module overridesmax_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.TypeErrorwhen its first route is declared, at import, not on its first request.ConnectorsRoute(TranslatingRoute)passes on the module's existingtranslatetable, which is unchanged.IngestRoute(BoundedBodyRoute)returnsMAX_LETTER_BYTES. The webhook bays callread_bounded(request, MAX_LETTER_BYTES), so it's still one cap across every ingest door.building-modules.mdsays where the bases live and how to subclass them. CLAUDE.md listsshared/routes.py. The comment instatic.pypoints atread_bounded's new home.Behaviour
No change:
CRM_INGEST_MAX_BODY_BYTESstill sets the cap.