clerk / clerk-sdk-python

52 stars 13 forks source link

Pydantic validation failure when fetching users with 'oauth_microsoft' enum #27

Closed soobinbhan closed 1 month ago

soobinbhan commented 1 month ago

When trying to fetch a user who has authenticated via microsoft, the client throws since the authentication strategy enum cannot be validated. This also occurs when trying to list all users of my application when at least one user has authenticated via Microsoft. Please add the value to the accepted list of enum values.

clerk = Clerk(bearer_auth=clerk_api_key)
outlook_test_user = clerk.users.get(user_id=outlook_test_user_clerk_id)
print(outlook_test_user)

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[13], line 1
----> 1 outlook_test_user = clerk.users.get(user_id=outlook_test_user_clerk_id)
      2 print(outlook_test_user)

File ~/.local/share/virtualenvs/-be-pxHlHy8Q/lib/python3.11/site-packages/clerk_backend_api/users.py:767, in Users.get(self, user_id, retries, server_url, timeout_ms)
    765 data: Any = None
    766 if utils.match_response(http_res, "200", "application/json"):
--> 767     return utils.unmarshal_json(http_res.text, Optional[models.User])
    768 if utils.match_response(http_res, ["400","401","404"], "application/json"):
    769     data = utils.unmarshal_json(http_res.text, models.ClerkErrorsData)

File ~/.local/share/virtualenvs/-be-pxHlHy8Q/lib/python3.11/site-packages/clerk_backend_api/utils/serializers.py:120, in unmarshal_json(raw, typ)
    119 def unmarshal_json(raw, typ: Any) -> Any:
--> 120     return unmarshal(from_json(raw), typ)

File ~/.local/share/virtualenvs/-be-pxHlHy8Q/lib/python3.11/site-packages/clerk_backend_api/utils/serializers.py:130, in unmarshal(val, typ)
    123 def unmarshal(val, typ: Any) -> Any:
    124     unmarshaller = create_model(
    125         "Unmarshaller",
    126         body=(typ, ...),
    127         __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
    128     )
--> 130     m = unmarshaller(body=val)
    132     # pyright: ignore[reportAttributeAccessIssue]
    133     return m.body

File ~/.local/share/virtualenvs/-be-pxHlHy8Q/lib/python3.11/site-packages/pydantic/main.py:193, in BaseModel.__init__(self, **data)
    191 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    192 __tracebackhide__ = True
--> 193 self.__pydantic_validator__.validate_python(data, self_instance=self)

ValidationError: 4 validation errors for Unmarshaller
body.email_addresses.0.verification.Otp.strategy
  Input should be 'phone_code', 'email_code', 'reset_password_email_code', 'from_oauth_discord', 'from_oauth_google' or 'from_oauth_apple' [type=enum, input_value='from_oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.email_addresses.0.verification.Admin.strategy
  Input should be 'admin' or 'from_oauth_discord' [type=enum, input_value='from_oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.email_addresses.0.verification.Oauth.strategy
  Input should be 'oauth_google', 'oauth_mock', 'from_oauth_google', 'from_oauth_discord' or 'oauth_apple' [type=enum, input_value='from_oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.email_addresses.0.linked_to.0.type
  Input should be 'oauth_google', 'oauth_mock', 'saml', 'oauth_discord' or 'oauth_apple' [type=enum, input_value='oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
speakeasybot commented 1 month ago

Thanks for reporting this! It has been addressed in the latest release: https://github.com/clerk/clerk-sdk-python/commit/a6c5d4efe16d30a626ee70ced55082617468254d