Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutate_object does not handle OneToOneFields #116

Open
lukavdplas opened this issue Aug 22, 2024 · 0 comments
Open

mutate_object does not handle OneToOneFields #116

lukavdplas opened this issue Aug 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@lukavdplas
Copy link
Contributor

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:

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

This does not account for the 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:

 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.

@lukavdplas lukavdplas added the bug Something isn't working label Aug 22, 2024
@lukavdplas lukavdplas moved this to Todo in Lettercraft Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

1 participant