Comments (3)
I stumbled onto the same problem when wanting to use the renderer.
I fixed it by overriding the renderer, short example here.
from django.utils.functional import Promise
from drf_orjson_renderer.renderers import ORJSONRenderer as OriginalORJSONRenderer
class ORJSONRenderer(OriginalORJSONRenderer):
@staticmethod
def default(obj):
# resolve promises/lazy values if needed
if isinstance(obj, Promise):
# django does it the same way internally,
# for example in the main `get_prep_value`
# impl for fields
obj = obj._proxy____cast()
return OriginalORJSONRenderer.default(obj)
It's using a private method, so could break anytime.
if @brianjbuck is fine with that approach, I also would be happy to provide a PR for this.
from drf_orjson_renderer.
Also, I just saw the default DjangoJSONEncoder
is doing:
elif isinstance(o, (decimal.Decimal, uuid.UUID, Promise)):
return str(o)
see here
from drf_orjson_renderer.
@syphar, Yes create a PR and I'll create a new release. Thanks for the assist 🙌
from drf_orjson_renderer.
Related Issues (8)
- drf_orjson_render 1.4.0 fail.
- Update to Django 4.0 HOT 1
- Python 3.6 dropped support is really necessary? HOT 2
- Dependency resolution fails with Django versions 4.0.x HOT 1
- ChoicesMeta is deprecated in favor of ChoicesType.
- Add CI configuration HOT 1
- ORJSONRenderer is causing malformed response on 204 replies HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf_orjson_renderer.