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

many_to_one_extras not correctly saving reverse relations #102

Open
calummackervoy opened this issue Dec 12, 2022 · 0 comments
Open

many_to_one_extras not correctly saving reverse relations #102

calummackervoy opened this issue Dec 12, 2022 · 0 comments

Comments

@calummackervoy
Copy link
Contributor

calummackervoy commented Dec 12, 2022

Expected Behaviour:

The following example is given in the documentation, for nested fields usingmany_to_one_extras:

class CreateUserMutation(DjangoCreateMutation):
    class Meta:
        model = User
        many_to_one_extras = {
            "cats": {
                "add": {"type": "auto"}
            }
        }

When running the following query, I expect Cats to be saved, and to have the owner of the freshly created user object

Current Behaviour:

I have Parent and Child models, where one Parent can have many children

For those models I've created the following types:

# Parent
class CreateParentMutation(DjangoCreateMutation):
    class Meta:
        model = Parent
        ...
        many_to_one_extras = {
            "children": {
                "add": {
                    "type": "CreateChildMutationInput",
                },
            }
        }

# Child
class CreateChildMutation(DjangoCreateMutation):
    class Meta:
        model = Child

This to me seems to be the same as the example. When running a query passing:

mutation createParent($input: CreateParentMutationInput!){
                createParent(input: $input) {
                    parent {
                        id
                        children {
                            id
                        }
                    }
                }
            }

I get the following error:

AssertionError: 'errors' unexpectedly found in ['errors', 'data'] : {'errors': [{'message': 'NOT NULL constraint failed: children_child.parent_id', 'locations': [{'line': 3, 'column': 17}], 'path': ['createParent']}], 'data': {'createParent': None}}

Which suggests that the reverse relation of child.parent hasn't been saved? I can't pass the parent's id into the children of the query obviously because it doesn't yet exist

I thought this might be related to #17 but I thought that it doesn't match the behaviour in the documentation, so maybe it's a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant