flagsmith
flagsmith copied to clipboard
refactor: Implement @with_metadata decorator to reduce boilerplate
This is a POC to solve #6277
Thanks for submitting a PR! Please check the boxes below:
- [ ] I have added information to
docs/if required so people know about the feature! - [ ] I have filled in the "Changes" section below?
- [ ] I have filled in the "How did you test this code" section below?
- [ ] I have used a Conventional Commit title for this Pull Request
Changes
Introduces a decorator pattern to automatically handle metadata in serializers, eliminating the need to manually override create(), update(), and validate() methods.
Changes:
- Add @with_metadata decorator in metadata/serializers.py
- Add helper functions _validate_required_metadata_for_model and _update_metadata_for_instance
- Refactor FeatureSerializerWithMetadata to use decorator pattern
- Reduce boilerplate
Benefits:
- Eliminates fragility: impossible to forget create() override
- No MRO issues: decorator works regardless of inheritance order
- More maintainable: metadata logic centralized in one place
- More explicit: @with_metadata makes intent clear
How did you test this code?
Please describe.
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| docs | Nov 12, 2025 6:05am | |||
| flagsmith-frontend-preview | Nov 12, 2025 6:05am | |||
| flagsmith-frontend-staging | Nov 12, 2025 6:05am |