BaseDjangoFormMutation should use from_global_id when fetching existing instance
See original GitHub issueWe are using DjangoFormMutations (#217), and what I’m not sure about is how Django’s ID/PKs are resolved in the process. They still appear in base64 encoding in the GraphQL output but in BaseDjangoFormMutation
method they are processed as is.
The error returned from GraphQL shows that the instance is fetched using the string with the base64 encoded ID instead of the decoded PK integer value.
"errors": [
{
"message": "invalid literal for int() with base 10: 'UHJvamVjdE5vZGU6MTA1'",
I think the following code from /graphene_django/forms/mutation.py should use from_global_id
instead of the value as is:
@classmethod
def get_form_kwargs(cls, root, info, **input):
kwargs = {'data': input}
pk = input.pop('id', None)
if pk:
instance = cls._meta.model._default_manager.get(pk=pk)
kwargs['instance'] = instance
return kwargs
I’m not 100% sure about this. We are using UUIDs next to Django’s IDs so I had to extend get_form_kwargs
anyway, and it works fine that way. But it’s not working for ID. If the above is the correct location for the fix I can create a pull request. Just wanted to check back if I’m understanding this correctly.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7
Top GitHub Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
IMO this issue should be closed and the documentation updated to explain how these hashed IDs are being created.