Skip to content

fix: add PolicyMfaFactors model to policy unions - #153

Open
Meldiron wants to merge 1 commit into
mainfrom
fix/policy-mfa-factors
Open

fix: add PolicyMfaFactors model to policy unions#153
Meldiron wants to merge 1 commit into
mainfrom
fix/policy-mfa-factors

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

Appwrite Cloud now returns an mfa-factors policy from GET /v1/project/policies (server model PolicyMFAFactors, added in appwrite/appwrite), but this SDK's unions predate it. As a result, every project.list_policies() call against Cloud currently crashes with:

AppwriteException: Unable to parse response into PolicyList: 23 validation errors for PolicyList
policies.10.PolicyPasswordDictionary.enabled
  Field required [type=missing, input_value={'$id': 'mfa-factors', ...}]
...

(caught by the Connect snippets QA in appwrite/vibes — all four python lanes fail; other SDKs parse leniently and are unaffected)

Changes, mirroring the generated style:

  • New appwrite/models/policy_mfa_factors.pyPolicyMfaFactors with totp / email / phone / custom booleans, matching the server's PolicyMFAFactors response model.
  • Added to the PolicyList.policies union and exported from appwrite.models.
  • Added to the get_policy return union, docstring, and $id dispatch in services/project.py.
  • Added MFA_FACTORS = "mfa-factors" to the ProjectPolicyId enum.

Not included: the update_mfa_factors_policy() service method (PATCH /v1/project/policies/mfa-factors) — the next spec regeneration will add it; this PR is the minimal fix for the parsing crash. If a regen is imminent, feel free to close this in favor of it — the vibes QA temporarily installs from this branch until a release containing the fix is on PyPI.

Test plan

PolicyList.model_validate({
    "total": 3,
    "policies": [
        {"$id": "password-strength", "min": 8, "uppercase": True, "lowercase": True, "number": True, "symbols": True},
        {"$id": "session-alert", "enabled": False},
        {"$id": "mfa-factors", "totp": True, "email": True, "phone": True, "custom": False},
    ],
})

parses successfully, with item 2 typed as PolicyMfaFactors; model_dump(by_alias=True) round-trips. Existing policy types still parse.

🤖 Generated with Claude Code

Appwrite Cloud now returns an mfa-factors policy from
GET /v1/project/policies, but the SDK's PolicyList and get_policy
unions predate it, so pydantic fails with "Unable to parse response
into PolicyList: 23 validation errors" for any project.list_policies()
call against Cloud.

Add the PolicyMfaFactors model (totp/email/phone/custom, mirroring the
server's PolicyMFAFactors response model), include it in the PolicyList
and get_policy unions and the get_policy dispatch, and add MFA_FACTORS
to the ProjectPolicyId enum.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown

Too many files changed for review (355 files, 200 file limit).

Bypass the limit by tagging @greptile-apps to review.

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.

1 participant