clerk / clerk-sdk-python

37 stars 9 forks source link

Pydantic failure from #27 persists. #36

Open soobinbhan opened 6 days ago

soobinbhan commented 6 days ago

Issue: Pydantic failure from #27 persists when calling clerk_client.users.list()

pydantic_core._pydantic_core.ValidationError: 9 validation errors for Unmarshaller
body.0.email_addresses.0.verification.Otp.attempts
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type
body.0.email_addresses.0.verification.Otp.expire_at
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type
body.0.email_addresses.0.verification.Admin.strategy
  Input should be 'admin' [type=enum, input_value='from_oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.0.email_addresses.0.verification.Oauth.strategy
  Input should be 'oauth_google', 'oauth_mock', 'from_oauth_google', 'from_oauth_discord', 'oauth_apple', 'oauth_microsoft' or 'email_link' [type=enum, input_value='from_oauth_microsoft', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.0.email_addresses.0.verification.Oauth.expire_at
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type
body.1.email_addresses.0.verification.Otp.attempts
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type
body.1.email_addresses.0.verification.Otp.expire_at
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type
body.1.email_addresses.0.verification.Admin.strategy
  Input should be 'admin' [type=enum, input_value='from_oauth_google', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
body.1.email_addresses.0.verification.Oauth.expire_at
  Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.8/v/int_type

https://github.com/clerk/clerk-sdk-python/blob/a6c5d4efe16d30a626ee70ced55082617468254d/src/clerk_backend_api/models/emailaddress.py#L25

Appears that OauthVerificationStrategy needs FROM_OAUTH_MICROSOFT="from_oauth_microsoft"

class OauthVerificationStrategy(str, Enum):
    OAUTH_GOOGLE = "oauth_google"
    OAUTH_MOCK = "oauth_mock"
    FROM_OAUTH_GOOGLE = "from_oauth_google"
    FROM_OAUTH_DISCORD = "from_oauth_discord"
    OAUTH_APPLE = "oauth_apple"
    OAUTH_MICROSOFT = "oauth_microsoft"
    **FROM_OAUTH_MICROSOFT = "from_oauth_microsoft"**
    EMAIL_LINK = "email_link"

I'm not sure why there are other validation failures.

logangingerich commented 6 days ago

Hi @soobinbhan! Apologies for the persisting issue here, we're applying some local fixes but also working on some upstream adjustments that should help address this long term. Would you mind updating to the most recently released version and see if there are any changes, particularly to the OAuth verification strategy? You can see the update to the referenced file here.

soobinbhan commented 5 days ago

@logangingerich Thanks for the update. I'm running into another validation issue:

{ "detail": "User not found: 4 validation errors for Unmarshaller body.email_addresses.0.verification.Otp.attempts Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/int_type body.email_addresses.0.verification.Otp.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/int_type body.email_addresses.0.verification.Admin.strategy Input should be 'admin' [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.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/int_type" }

https://github.com/clerk/clerk-sdk-python/blob/485cd2d224b365872e8a3ab71a01804b6157ac1c/src/clerk_backend_api/models/emailaddress.py#L112

Looks like the following line needs to be added:

class VerificationStrategy(str, Enum):
    ADMIN = "admin"
    **FROM_OAUTH_MICROSOFT = "from_oauth_microsoft"**

After adding this line, I can fetch users as expected.

roninio commented 5 days ago

I am getting this also

s = Clerk(bearer_auth=CLERK_API_KEY) res = s.users.get(user_id=user_id)

line 212, in init validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 4 validation errors for Unmarshaller body.email_addresses.0.verification.Otp.attempts Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type body.email_addresses.0.verification.Otp.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type body.email_addresses.0.verification.Admin.strategy Input should be 'admin' [type=enum, input_value='from_oauth_google', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/enum body.email_addresses.0.verification.Oauth.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type pydantic_core._pydantic_core.ValidationError: 4 validation errors for Unmarshaller body.email_addresses.0.verification.Otp.attempts Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type body.email_addresses.0.verification.Otp.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type body.email_addresses.0.verification.Admin.strategy Input should be 'admin' [type=enum, input_value='from_oauth_google', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/enum body.email_addresses.0.verification.Oauth.expire_at Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.9/v/int_type

roninio commented 5 days ago

seems you need to set.

class OtpTypedDict(TypedDict):
    status: VerificationStatus
    strategy: Strategy
    attempts: None
    expire_at: None

class Otp(BaseModel):
    status: VerificationStatus
    strategy: Strategy
    attempts: None
    expire_at: None
roninio commented 5 days ago

if I do as below: a = res.email_addresses why is it a list of EmailAddress Object?