Skip to content

fix: strawchemy fields on plain strawberry types fail with AttributeError instead of StrawchemyFieldError #391

Closed

Description

@gazorby

Found while working on #390.

A strawchemy.field whose type is a plain strawberry type (not a strawchemy type) is not rejected at definition, and then fails with an unrelated error:

Field Error
plain: list[Plain] = strawchemy.field() (root, no resolver) AttributeError: __dto_model__ at query time, from dto_model_from_type when get_result builds the repository
plain: list[Plain] = strawchemy.field(default_order_by=Color.name) AttributeError: type object 'Plain' has no attribute '__dto_model__' at definition, from the default_order_by block of StrawchemyField._validate_type
@strawberry.type
class Plain:
    name: str

The query hook model check (#388) is skipped for these fields too, since it only runs on strawchemy types.

Expected

StrawchemyField._validate_type (src/strawchemy/schema/field.py) raises StrawchemyFieldError at definition when a field that needs a strawchemy type (root field without resolver, default_order_by) has a plain strawberry type.

Activity

  1. changed the title [-]fix: strawchemy fields on plain strawberry types fail with AttributeError instead of StrawchemyFieldError[/-] [+]fix: strawchemy fields on plain strawberry types fail with `AttributeError` instead of `StrawchemyFieldError`[/+] on Sep 28, 2026
  2. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions