Skip to content

override_forbid_extra=True does not apply during v2 signon — UserSignOnV2 rejects extra fields #275

Description

@jgsart

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pyticktick.

Reproducible example

from pyticktick import Client

client = Client(
    v1_client_id="...",
    v1_client_secret="...",
    v1_token={"value": "...", "expiration": 123},
    v2_username="user@example.com",
    v2_password="password",
    override_forbid_extra=True,
)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Client
registerDate
  Extra inputs are not permitted by default. Please set `override_forbid_extra`
  to `True` if you believe the TickTick API has diverged from the model.
  [type=custom_pyticktick_extra_forbidden,
   input_value='2023-07-25T17:48:35.000+0000', input_type=str]

Log output

Issue description

The TickTick API now returns a registerDate field in the v2 signon response that UserSignOnV2 does not define. Since BaseModelV2 uses extra="forbid", validation fails.

override_forbid_extra=True does not help because v2_signon is a @classmethod — it calls UserSignOnV2.model_validate(resp) without access to self.override_forbid_extra and without calling update_model_config first.

This pattern works correctly for later API calls (e.g. get_user_profile_v2, get_batch_v2) where the instance method checks the flag and calls update_model_config(Model, extra="allow") before validation. But this is missing from the signon flow in Settings._get_v2_token() / v2_signon().

Expected Behavior

With override_forbid_extra=True, the client should accept extra fields in the v2 signon response, just like it does for other v2 API calls.

Current Workaround

Manually patch the model before creating the client:

from pyticktick.pydantic import update_model_config
from pyticktick.models.v2.responses.user import UserSignOnV2

update_model_config(UserSignOnV2, extra="allow")

client = Client(...)  # now v2 signon works

Suggested Fix

In Settings._get_v2_token() (or v2_signon), apply update_model_config(UserSignOnV2, extra="allow") when self.override_forbid_extra is True, before calling UserSignOnV2.model_validate(resp). Alternatively, add registerDate as an optional field to UserSignOnV2.

Is there a better or intended way to handle this that I'm missing?

Environment

  • pyticktick >= 0.0.3
  • Python 3.12
  • Windows

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions