Skip to content

test(model): pin from_resource schema-type coercion (issue #37) - #47

Merged
ngjunsiang merged 1 commit into
mainfrom
bugfix/model-from-resource-field-types
Sep 30, 2026
Merged

ngjunsiang merged 1 commit into
mainfrom
bugfix/model-from-resource-field-types

Conversation

@nycomp

@nycomp nycomp commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Issue #37 reported that Model.from_resource() returned plain builtins for fields declared as schema types (created_at as plain str instead of schema.DateTime), which is what let campus-cli call .isoformat() on a string and crash on every live client new / client get.

The coercion fix itself has already landed upstream in campus and is active in this repo's dependency pin — no production code change is needed here:

  • campus dfb7d0c (fix(model): deserialize init=False and nested fields in from_resource) added str→str-subclass coercion and nested-model deserialization to Model.from_resource(), with its own unit tests
  • campus ac9dfdc mirrored the coercion in from_storage()
  • both are included in campus-suite 9e37b85, which this repo's poetry.lock and venv already pin (PR chore(deps): bump campus-suite to weekly head 9e37b85 (campus #658 alignment check) #46)

Verified against the pinned campus-suite: Client.from_resource(...).created_at is schema.DateTime with working to_datetime(), id/email coerce to CampusID/Email, plain-primitive fields (str/bool/int) are untouched, and to_resource() round-trips JSON-serialisably.

What this PR does

Adds tests/unit/test_model_field_types.py pinning the field-type contract at this repo's boundary, following the same pattern as test_oauth_token_contract.py:

  • schema-typed fields (DateTime, CampusID, Email) are coerced on parsed resources, including the nested OAuthToken in UserCredentials and models returned by auth.clients.new() / .get() — the exact paths campus-cli consumes
  • emulated helpers (to_datetime(), Email.domain) are available on coerced fields
  • plain-primitive fields stay plain builtins; parsed models round-trip

If a future campus-suite bump regresses the coercion, CI fails here instead of in campus-cli.

Fixes #37

Test plan

  • .venv/Scripts/python.exe -m pytest: 89 passed (80 existing + 9 new)

@ngjunsiang
ngjunsiang merged commit d2fba82 into main Sep 30, 2026
2 checks passed
@nycomp
nycomp deleted the bugfix/model-from-resource-field-types branch September 30, 2026 11:16
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.

bug: Model.from_resource() does not cast fields to their declared schema types (created_at is plain str, not DateTime)

2 participants