strawberry-django-plus icon indicating copy to clipboard operation
strawberry-django-plus copied to clipboard

Unable to make a create mutation deeply nested with ManyToOnRel set

Open NwawelAIroume opened this issue 1 year ago • 1 comments

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 https://github.com/blb-ventures/strawberry-django-plus/blob/5e6b605e5f033ff3fddb9abfaf70e28cea1bd1f9/strawberry_django_plus/mutations/resolvers.py#L297 It should be a recursive call on create(...) instead of manager.create

NwawelAIroume avatar May 25 '23 16:05 NwawelAIroume