Skip to content

bug(core): resource classes do not enforce their own kind at construction time #1294

Description

@AlessandroPomponio

Summary

The kind field on core resource classes currently accepts any valid resource kind value at construction time, which means it's possible to accidentally create a resource with the wrong kind — for example, a discovery space resource tagged as an operation. This is a latent correctness issue that Pydantic could enforce automatically with a small type annotation change.

Motivation

Having an unconstrained kind field is a silent footgun: it bypasses the type system and allows objects to be constructed in an invalid state without any error. Tightening the type annotation to only accept the one valid value for each resource class would let Pydantic catch such mistakes at construction time, making the model layer more reliable and self-documenting. This is a low-risk, contained change that improves correctness without altering any public interfaces or runtime behaviour.

Scope

The change should cover all concrete core resource classes (there are five of them), each narrowing its kind field to only accept its own resource kind. Corresponding tests should be added to verify that passing a mismatched kind raises a validation error, while default construction continues to work as expected. No changes to the base resource class or the version field are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions