Skip to content

Conversation

@khvn26
Copy link
Member

@khvn26 khvn26 commented Dec 30, 2025

In this PR, we annotate DynamoDB schema types to enable their usage with Pydantic, when it's available.

It is now possible to use the document typed dicts with pydantic.TypeAdapter like so:

import json

from pydantic import TypeAdapter

from flagsmith_schemas.dynamodb import Identity

# Produce a ready to persist Dynamo document
TypeAdapter(Identity).validate_python(json.load(open("tests/integration/flagsmith_schemas/data/flagsmith_identities.json")))

The TypeAdapter will:

  • Validate if a feature state value string value length exceeds 20k characters.
  • Validate UUID strings, accepting both string and uuid.UUID values.
  • Validate datetime strings, accepting both string and datetime.datetime values.
  • Raise an error for multivariate feature states with total percentage_allocation higher than 100.
  • Raise an error when an identity document contains non-unique feature IDs.

The validation is intended to be used in Core API, when writing documents.

If pydantic not present, the schemas can still be used as plain typed dicts, i.e. to annotate data returned from DynamoDB.

@khvn26 khvn26 requested a review from a team as a code owner December 30, 2025 15:58
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team December 30, 2025 15:58
@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.33%. Comparing base (0b438e5) to head (b03fea2).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           feat/document-schemas     #148      +/-   ##
=========================================================
+ Coverage                  95.17%   95.33%   +0.15%     
=========================================================
  Files                         79       83       +4     
  Lines                       2676     2767      +91     
=========================================================
+ Hits                        2547     2638      +91     
  Misses                       129      129              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants