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.48%. Comparing base (9f9518b) to head (b08502f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   95.32%   95.48%   +0.15%     
==========================================
  Files          79       83       +4     
  Lines        2673     2767      +94     
==========================================
+ Hits         2548     2642      +94     
  Misses        125      125              

☔ 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.

@khvn26 khvn26 changed the base branch from feat/document-schemas to main January 5, 2026 17:34
@khvn26 khvn26 force-pushed the feat/document-schemas-annotated branch from 9567dee to 959bc8c Compare January 5, 2026 17:43
Zaimwa9
Zaimwa9 previously approved these changes Jan 5, 2026
Copy link
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with 2 NITs:

  • The naming might be quite subjective
  • The nested loop could be a low hanging fruit to solve now and buy some tranquility

@khvn26 khvn26 merged commit ff17838 into main Jan 5, 2026
3 checks passed
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.

4 participants