graphql-python / graphql-python/graphene

InputObjectType.__init_sublcass_with_meta__ skips Meta.fields attribute

Open
#1,429 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

In `InputObjectType.__init_subclass_with_meta__`, the `fields` of the `Meta` class (passed as an `options` arg) are never referenced. This in effect just skips them completely wich stands in contradiction to the docstring.

```
Meta class options (optional):
...
fields (Dict[str, graphene.InputField]): Dictionary of field name to InputField. Not
recommended to use (prefer class attributes).
```

`InputObjectType` has to be subclassed and `__init_subclass_with_meta__` has to be extended for this feature to work, like in [graphene.tests.issues.test_720](https://github.com/graphql-python/graphene/blob/efe4b89015d56a0b6c81abc6c0b4e46984aefd11/graphene/tests/issues/test_720.py#L9).

If this is accepted I can do a PR for this along the lines:
```diff
@classmethod
+ def __init_subclass_with_meta__(cls, container=None, _meta=None, fields=None **options):
- def __init_subclass_with_meta__(cls, container=None, _meta=None, **options):
if not _meta:
_meta = InputObjectTypeOptions(cls)

+ if not fields:
+ fields = {}
- fields = {}
for base in reversed(cls.__mro__):
fields.update(yank_fields_from_attrs(base.__dict__, _as=InputField))

if _meta.fields:
_meta.fields.update(fields)
else:
_meta.fields = fields
if container is None:
container = type(cls.__name__, (InputObjectTypeContainer, cls), {})
_meta.container = container
super(InputObjectType, cls).__init_subclass_with_meta__(_meta=_meta, **options)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at InputObjectType.__init_subclass_with_meta__ and compare its handling with the documented Meta.fields option. Review graphene/tests/issues/test_720.py for the referenced behavior. Done means Meta.fields is preserved and covered by a test demonstrating that subclassing InputObjectType does not discard those fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.