Giter VIP home page Giter VIP logo

Comments (11)

krzysieqq avatar krzysieqq commented on June 22, 2024 4

I think that the problem is a little more complicated. I was trying to debug this but I didn't find any fast fix. The problem could start in Django middlewares, and it seems that one of them, opens the file in stream buffer before it goes to this package. When a request goes into renderer it doesn't come into parse function because it stops earlier. More precisely it stops in rest_framework/requests.py:321 _parse() function, requests falls into first try/except then go into 336 if which return True, and return values in 337 line.

@vbabiy I'll try to write test in few hours/days

from djangorestframework-camel-case.

vbabiy avatar vbabiy commented on June 22, 2024 1

If anyone can help me with a test case, I can try to get this fixed.

from djangorestframework-camel-case.

banagale avatar banagale commented on June 22, 2024 1

I’ll try to find the project this was happening on.

from djangorestframework-camel-case.

vbabiy avatar vbabiy commented on June 22, 2024

@serendipity1004 can you test the latest version, if not PR with at least a test would be really helpful.

from djangorestframework-camel-case.

banagale avatar banagale commented on June 22, 2024

@vbabiy First, this is a really great package. Its nice to have the automated sanity of the correct casing on frontend and backend. I don't know how people do DRF without it, (it should be built into DRF!). So thank you for your work on it.

I noticed that it seems to not work on ImageField as well.

I'm running Django 3.1.3, DRF 3.12.2 and DRF-C-C 1.2.0.

In my case the frontend would prepare the POST data like:

    const getInputData = async () => {
      let input = document.getElementById('profile-photo-input');
      const formData = new FormData();
      data.append('profile_photo', input.files[0]);
      return formData;
    };

And then the serializer that takes it looks like:

class UserProfilePhotoSerializer(serializers.Serializer):  # noqa
    profile_photo = serializers.ImageField(required=True)

Trying to send up camel case from the frontend failed, so I have to use the snake case as per the line above data.append('profile_photo')...

I'd be happy to try and provide more useful info, if you can clarify what could be added that would be useful I'll try and get it in this issue or a PR.

from djangorestframework-camel-case.

krzysieqq avatar krzysieqq commented on June 22, 2024

Try to use PUT instead of POST method in my case it helped.

from djangorestframework-camel-case.

tremlab avatar tremlab commented on June 22, 2024

Having the same issue. 😢 Has anyone else found a solution? I see there are a few other similar packages out there...has anyone tried them?
https://pypi.org/search/?q=djangorestframework-camel-case

Unfortunately I can't switch from POST to PUT, but do you have any idea what exactly is broken about the POST? @krzysieqq

Thanks!

from djangorestframework-camel-case.

tremlab avatar tremlab commented on June 22, 2024

It is very complicated! I tried to follow the code but still don’t understand what is happening. @krzysieqq

For me, the root failure happened here:

…/lib/python3.7/site-packages/rest_framework/fields.py

def to_internal_value(self, data):: https://github.com/vbabiy/djangorestframework-camel-case/releases
    try:
        # `UploadedFile` objects should have name and size attributes.
        file_name = data.name
        file_size = data.size
    except AttributeError:
        self.fail('invalid')

The function expects the data argument to be a file, but in my case it is a LIST containing one file. So file.name blows up. No idea how this is connected to the camel_case package. 🤷‍♀️🤣

The bug does not occur in djangorestframework-camel-case v0.2.0. I see the error when trying to upgrade to v1.2.0. User above also reported the issue in v1.1.2. I can’t quite follow what is going on with the releases here: https://github.com/vbabiy/djangorestframework-camel-case/releases but - I have everything queued up locally. If someone could give me a list of the versions between these, I can try to bissect which exact version introduced the bug (if that helps.)

I’m using:

python 3.7.10
djangorestframework==3.8.1

I want to second this @banagale : “First, this is a really great package. Its nice to have the automated sanity of the correct casing on frontend and backend. I don't know how people do DRF without it, (it should be built into DRF!). So thank you for your work on it.” And also thanks for responding so quickly!!!!! 🙏 @vbabiy

from djangorestframework-camel-case.

krzysieqq avatar krzysieqq commented on June 22, 2024

It's funny but I'm unable to recreate bug at new project. I also try to recreate in another project i which i had this problem, but i also I can't. I'll later try to recreate maybe

from djangorestframework-camel-case.

banagale avatar banagale commented on June 22, 2024

It's funny but I'm unable to recreate bug at new project. I also try to recreate in another project i which i had this problem, but i also I can't. I'll later try to recreate maybe

I think this is what happened for me! I ran into an issue, reported it here, then I think it uh, “went away.” I don’t remember fixing it but more like, “maybe I was mistaken about this being broken.”

I was going to mention that in my most recent reply, but it didn’t seem like that did much to stand up my previous report of the issue.

I would have wanted to have provided some follow-up that it was intermittent or something more descriptive than leaving it as though it happened and no work-around was found.

from djangorestframework-camel-case.

eugene-babichenko avatar eugene-babichenko commented on June 22, 2024

I encountered this problem myself. Turns out, when explicitly specifying parser_classes you have to use CamelCaseMultiPartParser instead of DRF's MultiPartParser. That's it, that's the problem. Very easy to miss, very hard to spot.

from djangorestframework-camel-case.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.