Skip to content

fix: Incorrect to_schema generation for dataclass using ResultConverter #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Kumzy
Copy link
Member

@Kumzy Kumzy commented May 22, 2025

Not sure that is the best way to fix the issue.

Description

The following code was not working and returned SQLSpecError: `schema_type` should be a valid Dataclass, Pydantic model or Msgspec struct

#Import there

@dataclass
class SampleDataclass:
    """Sample dataclass for testing."""

    name: str
    value: int | None = None
    empty_field: Any = Empty
    meta: ClassVar[str] = "test"

data = ResultConverter.to_schema(data=SampleDataclass(name="test", value=42), schema_type=SampleDataclass)

I tried to replace the is_dataclass by the built in is_dataclass from dataclasses, it correctly identify whether the passed argument is a dataclass type (if it's a class) or an instance of a dataclass. Where the method in typing was working only when it was an instance of the class.

There was a fail also right after when trying to cast the dictionary into the dataclass.

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.

1 participant