Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Unable to make a create mutation deeply nested with ManyToOnRel set #211

Open
NwawelAIroume opened this issue May 25, 2023 · 1 comment
Open

Comments

@NwawelAIroume
Copy link

Deeply nested create mutation is not working for the case where I have 3 models A, B, C.

The issue is in the field of Model B which is ManyToOneRel with Model C

Here is the use case:
Model A -> OneToOne Model B -> ManyToOneRel -> Model C

Model A => ProjectFinance
Model B => Transaction
Model C => TransactionLine

I get the error when making a deeply nested create mutation on Model A including nested Model B and Model C
image

But i get a successfull mutation when making deeply nested create mutation on Model B including Model C
image

here is the stack trace

File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry/extensions/base_extension.py", line 46, in resolve
return _next(root, info, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry_django_plus/directives.py", line 119, in resolve
return _next(root, info, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 564, in _resolver
return _get_result_with_extensions(_source, strawberry_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 538, in _get_result
return field.get_result(
^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry/field.py", line 178, in get_result
return self.base_resolver(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry/types/fields/resolver.py", line 187, in call
return self.wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/ast_mgr/backend/api/gql/mutations/init.py", line 1531, in projectfinance
return resolvers.create(info, ProjectFinance, resolvers.parse_input(info, data))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry_django_plus/mutations/resolvers.py", line 218, in create
return update(info, model(), data, full_clean=full_clean)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/home/iroume/prj/prj/venv/lib/python3.11/site-packages/strawberry_django_plus/mutations/resolvers.py", line 307, in update
value = field.related_model._default_manager.create(**value_data) # noqa: PLW2901

I think the issue is on the line

value = field.related_model._default_manager.create(**value_data) # noqa: PLW2901

It should be a recursive call on create(...) instead of manager.create

@bellini666
Copy link
Member

Hey @NwawelAIroume ,

Hrm, that is interesting.

Would you like to try to open a PR for that case? If you don't have the time for that, I'll try to take a look at that in the next weeks

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

No branches or pull requests

2 participants