ApprovalHandlingMixin: 409 body ignores approvals read scope, and its docstring leaks into consumers' public API docs
ApprovalHandlingMixin in products/approvals/backend/mixins.py is inherited by six viewsets. Two of its behaviors affect all of them, so neither belongs in a single consumer's PR. Both came up while reviewing #106913.
1. The 409 body carries the whole change request
handle_exception() embeds the full ChangeRequestSerializer output in the conflict response, including the intent, the policy snapshot, the requester, and the approvals.
A caller holding only survey:write (or experiment:write, or any other consumer's scope) can trip the gate and read that object back without approvals:read.
Options: return only status and change_request_id, or check the approvals read scope before including the serialized object.
2. The mixin docstring becomes the public description of its consumers' endpoints
drf-spectacular walks the MRO for a viewset description. A viewset that inherits the mixin and has no docstring of its own publishes the mixin's implementation notes as the description of every one of its endpoints.
This is live today. "Mixin for ViewSets to handle approval-gate exceptions raised from decorated serializers." currently appears in:
products/experiments/frontend/generated/api.tsproducts/experiments/frontend/generated/api.zod.tsservices/mcp/src/generated/experiments/api.tsproducts/desktop/packages/api-client/src/generated.ts
So agents calling the experiments MCP tools read the mixin's internals as the endpoint description.
Adding a docstring to each consumer works but leaves the trap set for the next one. Turning the mixin's docstring into a comment fixes every consumer at once, because a comment cannot be inherited through the MRO. That needs a regen of the affected generated types.
Source: PostHog/posthog