Allow Only Caller-Writable Properties
Review explicit request fields, DRF serializers, partial updates, nested relationships, and server-owned privilege or billing state.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
Owning a profile does not mean owning every field
Object property authorization decides which properties a caller may read or write. Mass assignment is a common failure on the write side: the application maps client-supplied fields onto a persistence model without limiting them to the intended operation. The object itself can be correctly scoped to the current user.
In MemberHub, a customer may edit a display name and biography. The same profile row also stores a subscription tier, reward points, a user relationship, and a custom is_staff flag. Those values serve other workflows. The customer owning this row does not make them customer-writable.
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = '__all__'
profile = request.user.profile
serializer = ProfileSerializer(profile, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
The lookup uses request.user.profile, so changing the object ID is unnecessary. The review asks what the serializer generates as writable fields, what validators run, and what save() persists. Framework defaults may make some fields read-only, such as certain generated identifiers; do not assume every model field is writable merely from __all__. Inspect the generated serializer and model definitions.