GithubHelp home page GithubHelp logo

amertz08 / drf_ujson2 Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 5.0 29 KB

JSON parser and renderer using ujson for Django Rest Framework

License: MIT License

Makefile 3.37% Python 96.63%
django django-rest-framework python python3 ujson

drf_ujson2's People

Contributors

amertz08 avatar carlkibler avatar johnthagen avatar muslimbeibytuly avatar pasevin avatar patrickdamery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

drf_ujson2's Issues

Advertise JSON decoder more visibly?

Hi!

I think the JSON decoding part is at least as interesting as the encoding part (because it's faster and rejects single surrogates as invalid). So it's great you move off drf-ujson-renderer for a name. However the descriptions have not caught up yet: On the GitHub repo, on PyPI and in the readme. I propose these changes:

--- Django Rest Framework UJSON Renderer
+++ Django Rest Framework UJSON Parser and Renderer

--- Django Rest Framework renderer using ujson
+++ Django Rest Framework JSON parser and renderer using ujson

--- New repo for forked from https://github.com/Amertz08/drf-ujson-renderer
+++ JSON parser and renderer using ujson for Django Rest Framework

PS: This page I created today may be of interest: https://djangopackages.org/grids/g/drf-json-decoder-integration/

Update ujson dependency

Hello,

within a Pretix deployment in our team, we had issues with incompatible versions of ujson and drf_ujson.

This library (drf_ujson2) uses the default parameter from ujson in renderers.py#L44. This parameter is introduced in version 4.2.0 of ujson. However, drf_ujson2 only enforces ujson>=2.0.1 as dependency.

From my point of view, we should change this dependency to at least ujson>=4.2.0. Are there any objections against this proposal?

anaconda

hi
Could you please publish package on Anaconda cloud anaconda.org for conda users ?

Thank you.

TypeError thrown when serializing UUIDField

Issue rendering UUID field as foreign key

  • TypeError encountered when serializing certain models
  • Category objects could be rendered successfully
  • Photo objects throw TypeError when using UJSONRenderer
  • JSONRenderer works fine

Output from shell

>>> p = Photo.objects.all()[0]
>>> p
<Photo: LE123: Photo_L*>
>>> s = PhotoSerializer(p)
>>> s.data
{'id': 4875, 'name': 'LE123 Photo_L.jpg', 'image': '/images/LE123_Photo_L.jpg', 'product': UUID('ffdce82f-f094-499a-b221-2b49ec9c36ff')}
>>> UJSONRenderer().render(s.data)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/drf_ujson/renderers.py", line 42, in render
    indent=indent or 0,
TypeError: �1a-�� is not JSON serializable

>>> from rest_framework.renderers import JSONRenderer
>>> JSONRenderer().render(s.data)
b'{"id":4875,"name":"LE123 Photo_L.jpg","image":"/images/LE123_Photo_L.jpg","product":"ffdce82f-f094-499a-b221-2b49ec9c36ff"}'

Models & Serializers

class Category(OrderedModel):
    category = models.CharField(max_length=50)
    order = models.PositiveIntegerField(_("order"), editable=False, db_index=True)

class Product(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    ...
    category = models.ManyToManyField(Category)

class Photo(models.Model):
    name = models.CharField(max_length=500, null=True)
    image = models.ImageField(null=True)
    product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)

class PhotoSerializer(serializers.ModelSerializer):
    class Meta:
        model = Photo
        fields = "__all__"


class ProdSerializer(serializers.ModelSerializer):
    category = serializers.StringRelatedField(many=True)
    photo_set = PhotoSerializer(many=True)

    class Meta:
        model = Product
        fields = "__all__"


class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = Category
        fields = "__all__"
  • Suspect it might be due to the UUID reference in the Photo object?
  • Any suggestions on how to resolve this would be great

Original ujson is dead — move to...?

Hi!

Plain ujson is dead upstream and fails to import due to link errors with recent Python, e.g. 3.7. I have been looking out for ujson-based alternatives and documented my findings at python-rapidjson/python-rapidjson#130 (comment) .

Out of those only ujson-segfault seems like an option to me. There is also resurrection happening at https://github.com/ultrajson/ultrajson-fork starting off ultrajson/ultrajson#343 (comment) but the code is not on PyPI yet, to my best knowledge.

Best, Sebastian

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.