ModelCardGQL.from_pydantic crashes: resolver-backed min_resource passed to __init__
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
## Bug
Every v2 model card GraphQL query (`adminModelCardsV2`, `scopedModelCardsV2`, node fetch, mutations returning `ModelCardV2`) fails with:
```
ModelCardGQL.__init__() got an unexpected keyword argument 'min_resource'
```
The failure is independent of the client's field selection — even `{ adminModelCardsV2(limit: 1) { edges { node { id } } } }` fails. REST v2 (`/v2/model-cards`) is unaffected.
## Root cause
Introduced in bd94f48db7 (#13708, BA-7297): `ModelCardGQL.min_resource` became an on-demand **resolver field** (reads `model_card_resource_requirements` lazily), while the `ModelCardNode` DTO (`common/dto/manager/v2/model_card/response.py`) still carries a `min_resource` field.
`_from_pydantic_kwargs()` in `manager/api/gql/pydantic_compat.py` maps every GQL dataclass field that has a same-named DTO attribute into constructor kwargs. Resolver-backed Strawberry fields are excluded from `__init__` (`field.init == False`), so passing `min_resource` raises `TypeError`.
## Fix
Skip dataclass fields with `init=False` in `_from_pydantic_kwargs()` — this fixes the whole class of bugs for any node type that pairs a DTO field with a resolver-backed GQL field.
## Repro
```bash
./bai gql '{ adminModelCardsV2(limit: 1) { count edges { node { id name } } } }'
```
Contributor guide
Research direction
Start in manager/api/gql/pydantic_compat.py at _from_pydantic_kwargs(), then compare the resolver-backed ModelCardGQL.min_resource field with the ModelCardNode DTO in common/dto/manager/v2/model_card/response.py. Reproduce the failure with ./bai gql '{ adminModelCardsV2(limit: 1) { count edges { node { id name } } } }'. Done when the query and the other listed ModelCardV2 GraphQL operations no longer pass resolver-backed fields to the constructor.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100