Comments (3)
There's a lot to unpack here.
The following two patches made it work. I think the first one is a bug as it detects wrongly
int | str | None
as anOptional[int]
.
That's indeed not correct, though I don't think your patch is a good solution. int | str | None
actually is an optional type (optional really just means nullable), but it should be Optional[int | str]
, not Optional[int]
.
The second patch allows mapping UnionType aliases to Field serializers but does not support overriding other kinds of aliases.
This part looks correct to me.
In this case, the library calls
lookup_type_in_mapping
using JsonPrimitive rather than JsonKV. To be honest, I don't know which is the best approach to solve this or even if this should be supported. It makes sense for our dynamic serializers though.
I agree it's not a bad idea to support this, though I'm also not immediately sure of the best way to support this.
from djangorestframework-dataclasses.
The following two patches made it work. I think the first one is a bug as it detects wrongly
int | str | None
as anOptional[int]
.That's indeed not correct, though I don't think your patch is a good solution.
int | str | None
actually is an optional type (optional really just means nullable), but it should beOptional[int | str]
, notOptional[int]
.
This has been fixed in e26c57a (and follow-up bc8d79a).
The second patch allows mapping UnionType aliases to Field serializers but does not support overriding other kinds of aliases.
This part looks correct to me.
This has been fixed in be6359b (I forgot to credit you, sorry about that).
I'll leave this issue open for your last point, though I'm not sure right now if and how that can be fixed.
from djangorestframework-dataclasses.
Hi @oxan,
Thank you for taking the time to respond and fix that bugs!!! I very much appreciate it. And, my apologies for putting so much stuff in a single issue; these were unrelated things.
Regarding the last point, we can leave this as it is. If we reencounter this problem, we'll try to solve it ourselves and then post some proposal here. And no worries about the credit; not needed at all, we are happy just helping a bit.
from djangorestframework-dataclasses.
Related Issues (20)
- Serializing nested dataclasses using rest_framework.serilaizers.Field subclass HOT 2
- Performance ModelSerializer vs DataclassSerializer
- Type forward references do not work with PEP 585 collections HOT 5
- Nested dataclasses and using drf-spectacular. HOT 7
- [Question]: Nested serializer with Union HOT 2
- For nested dataclass serializers, prefix with the name of dataclass so drf-spectacular doesn't combine components HOT 6
- Difference between inheritance and function HOT 3
- TYPE_CHECKING imports result in error on type evaluation HOT 8
- Nesting dataclass serializer inside regular serializer can result in <class 'rest_framework.fields.empty'> for optional fields HOT 3
- "Invalid data. Expected a dictionary, but got <dataclass.type>" HOT 2
- bool field with default of True actually defaults to False when using QueryDict HOT 4
- Adding support for dataclass Union field HOT 8
- Mypy error: Type argument "X" of "DataclassSerializer" must be a subtype of "Dataclass" HOT 3
- Bug with @swagger_auto_schema in drf-yasg HOT 1
- Support for types like frozenset? HOT 8
- Serializer initializing dataclass with non init fields
- Why lock on dataclass?
- DataclassListSerializer can't deserialize objects HOT 2
- DataclassSerializer fails with `source="*"` embedded serialiser fields because it requires Meta.dataclass HOT 7
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 djangorestframework-dataclasses.