Skip to content

docs: QueryHook.apply_hook docstring misdescribes alias for relation-field hooks #400

Description

@gazorby

The QueryHook.apply_hook docstring (src/strawchemy/transpiler/hook.py:198) says:

alias is the alias of the model the hook's field belongs to.

This is wrong for a hook on a relation field. StrawchemyRepository._build attaches that hook to the child node (src/strawchemy/repository/strawberry/base.py:337: self._add_query_hooks(hooks, child if is_relation_field else node)), so alias is the related model's alias. _check_query_hooks in src/strawchemy/schema/factories/base.py and test_relation_field_hook_of_another_model agree with this.

The class docstring ("Loads extra columns and relations, or edits the SELECT, for the field it is attached to") also leaves out type-level hooks (@strawchemy.type(query_hook=...)) and repository hooks.

Suggested wording: "alias is the alias of the model the hook runs on: the related model for a relation field, the type's model otherwise." docs/reference/api/hooks.md picks it up when regenerated.

Activity

  1. gazorby commented on Sep 29, 2026

    @gazorby
    OwnerAuthor

    Fixed on the docs-website branch: the apply_hook docstring describes alias as the model the hook runs on (the related model for a relation field), and the class docstring covers type, field and repository hooks.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions