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

<InMemoryUploadedFile: logo_Reverse.svg (image/svg+xml)> is not JSON serializable ... but other uploads work fine. #32

Open
japrogramer opened this issue Apr 24, 2019 · 9 comments

Comments

@japrogramer
Copy link

japrogramer commented Apr 24, 2019

I have made file uploads before, and they work.
However here i must have found a bug in graphene-file-upload.

{"errors":[{"message":"<InMemoryUploadedFile: Welnity_logo_Reverse.svg (image/svg+xml)> is not JSON serializable"}]}
@japrogramer japrogramer changed the title File upload not serializable. but only in one file upload. others work fine. <InMemoryUploadedFile: logo_Reverse.svg (image/svg+xml)> is not JSON serializable ... but other uploads work fine. Apr 24, 2019
@japrogramer
Copy link
Author

japrogramer commented Apr 24, 2019

It seems that the error happens in django_graphene .. but its odd. I think it only happens for the in memory file upload.

what is odd, is that it only seems to be happening on one of my posts,
as seen above.

@japrogramer
Copy link
Author

japrogramer commented Apr 24, 2019

this was the problem

graphql/execution/values.py(70)get_variable_values()
-> if errors:

(Pdb) errors
['In field "position": Expected "String!", found null.']

this means that this package is hiding errors. somehow

@ungaro
Copy link

ungaro commented May 11, 2019

hi, how did you resolve this issue? I'm having same problem, i do have a mutation that is working perfectly fine, and another mutation that throws Object of type InMemoryUploadedFile is not JSON serializable

@japrogramer
Copy link
Author

japrogramer commented May 11, 2019

it means that you are not passing an expected input. like in my previous comment shows the actual error is

hidden by graphene-file-upload
in my instance i was missing the position
class JobInput(InputProto):
    anonymous = graphene.Boolean()
    title = graphene.String()
    attachment = Upload(required=False)
    new_categories = graphene.List(graphene.String)

    class Meta:
        model = Job
        fields = (
            'hidden',
            'description',
            'location',
            'organization',
            'title',
            'position',
            'application_link',
            )
        _generic = {'required': False}
        fields_kwargs = {
            'location': _generic,
            'hidden': _generic,
            }

...

class CreateJob(graphene.Mutation):
    status = graphene.Int()
    errors = generic.GenericScalar()

    class Arguments:
        details = JobInput(required=True)

@ungaro
Copy link

ungaro commented May 11, 2019

@japrogramer Thanks for the info, yes it seems there is a totally unrelated error in the input data, just wasted 3 hours on this.

For future reference to new users, i was able to pinpoint the error by removing arguments one by one and find a combination when it works so i can inspect which argument was causing the error.

@Thousif-S
Copy link

@japrogramer , @ungaro It will be a great help if you can solve this, I'm getting the error Object of type "VersatileImageFieldFile is not JSON serializable" while trying to upload image but after that when I query back it shows the uploaded content how to pass the error 500 internal server error

@ungaro
Copy link

ungaro commented Jul 27, 2019

@Thousif-S I would do following to resolve this issue:

1-Remove the VersatileImageFieldFile from your Mutation. Test it from the graphql view with arguments. Does it work now?
2 Change the VersatileImageFieldFile to ImageField. Test it from the graphql view with arguments. Does it work now?

Unfortunately graphene-file-upload hides the real error, so that makes you think that it's related to graphene-file-upload, but in the end it was another error that i was not aware of.

In my case it was related to another field expecting different type of argument.

@Thousif-S
Copy link

@ungaro Thanks for your swift reply , After making a bunch of tries It worked out, still can't figure out what went wrong though.
P.S. I forgot to check your reply till today, but thanks for your reply ☺☺☺

@kingzbauer
Copy link

kingzbauer commented Apr 3, 2020

as mentioned by @japrogramer there is an obscured error underneath, a field that is failing validation against its defined type. Graphql is trying to serializer the input from the client (so as to display the first validation error) which happens to include an uploaded file, which is not json serializable.
#31 (comment)

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

4 participants