Skip to content

Conversation

@gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Nov 12, 2025

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.

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 from 32 lines to 17 lines (47% reduction)

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

Related to #6170, #6172 - part of metadata architectural improvements
@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs Ignored Ignored Nov 12, 2025 6:05am
flagsmith-frontend-preview Ignored Ignored Nov 12, 2025 6:05am
flagsmith-frontend-staging Ignored Ignored Nov 12, 2025 6:05am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants