Skip to content

fix: root_aggregations on a plain strawberry type fails at query time instead of definition #390

Description

@gazorby

Found while reviewing #389.

StrawchemyField._validate_type (src/strawchemy/schema/field.py) raises StrawchemyFieldError when root_aggregations is enabled on a field whose type is not a root aggregation type, but only for strawchemy types: a plain strawberry type is skipped. A root field without resolver then builds a repository at execution, and dto_model_from_type fails with AttributeError on __dto_model__.

Reproduction

@strawberry.type
class Plain:
    name: str

@strawberry.type
class Query:
    plain: list[Plain] = strawchemy.field(root_aggregations=True)

Schema builds; querying plain raises AttributeError instead of a StrawchemyFieldError at definition.

Expected

root_aggregations on a field whose type is not a strawchemy root aggregation type raises StrawchemyFieldError at definition, plain strawberry types included (at least for root fields without a custom resolver).

Activity

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