Skip to content

Handle lazily exposed class annotations in class-schema validation#17

Merged
harumaki4649 merged 2 commits intomainfrom
copilot/fix-validation-error-tests
Mar 8, 2026
Merged

Handle lazily exposed class annotations in class-schema validation#17
harumaki4649 merged 2 commits intomainfrom
copilot/fix-validation-error-tests

Conversation

Copy link
Contributor

Copilot AI commented Mar 8, 2026

Class-based schemas could be misdetected as empty on Python 3.14, causing required annotated fields to be skipped instead of raising ValidationError. This primarily affected schemas defined only with annotations, e.g. name: str, age: int.

  • Root cause

    • Class-schema detection and schema generation assumed __annotations__ always lived in cls.__dict__.
    • On newer Python behavior, annotations may be exposed lazily, so annotation-only schemas could bypass required-field validation.
  • Implementation

    • Added a small helper to read class annotations from either:
      • the class __dict__, or
      • a lazily exposed __annotations__ attribute
    • Updated both:
      • class-schema detection (_is_class_schema)
      • class-to-schema conversion (_class_to_schema)
    • Preserved existing behavior around inherited annotations and non-schema classes.
  • Regression coverage

    • Added a focused test that simulates lazily exposed annotations and verifies missing required fields still raise ValidationError.
class Profile:
    name: str
    age: int

validate({"name": "Alice"}, Profile)
# expected: ValidationError(path="age")

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • docs.python.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix validation error tests for schema validation Handle lazily exposed class annotations in class-schema validation Mar 8, 2026
@harumaki4649 harumaki4649 marked this pull request as ready for review March 8, 2026 12:23
@harumaki4649 harumaki4649 merged commit c14deb7 into main Mar 8, 2026
37 checks passed
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.

2 participants