CentreForDigitalHumanities / CentreForDigitalHumanities/lettercraft

mutate_object does not handle OneToOneFields

Open
#116 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
1
Forks
0
Avg merge
2d 6h
Merged PRs (30d)
10

Description

The `mutate_object` method of the `LettercraftMutation` (for handling mutation requests to the backend) has separate handlers for relational fields. The method decides on the handler by checking `field.many_to_many` and `field.many_to_one`:

https://github.com/CentreForDigitalHumanities/lettercraft/blob/dd3fb51ef2bd3f5eb8f2745608d4b340c98c49c5/backend/graphql_app/LettercraftMutation.py#L110-L115

This does not account for the [OneToOneField](https://docs.djangoproject.com/en/5.1/ref/models/fields/#onetoonefield) - this is also a relational field, but it is not `many_to_many` or `many_to_one`, so it won't be handled properly and the mutation will return an error.

A OneToOneField is essentially a ForeignKey with a uniqueness requirement. I *think* you could just use the handler for ForeignKey fields here. In that case, you could just adjust this tree as follows:

```py
if field.many_to_many is True:
many_to_many_fields.append(key)
elif field.is_relation is True:
one_to_many_fields.append(key)
else:
simple_fields.append(key)
```

I didn't test this yet, however.

Contributor guide

Open the contributing guide

Research direction

Start in backend/graphql_app/LettercraftMutation.py around lines 110-115 and inspect how mutate_object classifies relational fields. Reproduce a mutation involving a Django OneToOneField, then confirm it is handled without an error and that existing many-to-many, foreign-key, and simple-field behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.