Comments (7)
Custom error handling isn't so necessary there now we have add_error
. This does lead to the idea that a ValidationError
could just be bound to two fields and displayed however the renderer wants. That said, sometimes although the validation crosses fields, the error is explicitly about one of the fields.
Another edge case I've just thought of which I'm not sure how well it fits, and definitely isn't clearly mirrorable, is validation which depends on a hidden aspect of the bound intial object(s). It would seem a bit clunky to require constructing the serializer using the instance we are going to operate on AND then having to pass it to the initial step. It kinda opens up a question about read/write patterns - if we have a read only field which is marked as hidden for renderers then we can cross field validate using it later. The balance between read/write different behaviour on the same object and having distinct objects for read/write is an interesting one.
from django-adapters.
I like this. A clear distinction between validation and cleaning may also be useful for distinguishing validation that can only happen on the backend and validation that may also run on the frontend.
In your structure above, it seems to me that any Validator
that only overrides validate
is a candidate for a frontend mirror, whereas one that overrides clean
is not.
Perhaps some data transformations can considered cheap and idempotent, like int(value)
, so maybe they can be mirrored too. But this would require that they don't break earlier validators too, so this is a lot more complex to allow.
from django-adapters.
The problem is, if a "plain" validator depends on a cleaning one, then you need to mirror them all.
from django-adapters.
Yeah... it's probably impossible to handle in the generic case. That shouldn't stop us thinking about how to support a subset though.
from django-adapters.
One really shiny thing that a tree/dag of validators/cleaners allows is a ValidationError
will only prevent dependent validators from running. This is much nicer than the current case where a This is nicer than checking manually in Form.clean
method only runs if all other validators pass.Form.clean
which fields have been successfully cleaned and which have failed validation.
from django-adapters.
I think my crossed-out comment does apply to a DRF Serializer.validate
method.
The structure also allows raising more than one cross-field ValidationError
without needing custom error handling within the Form.clean
or Serializer.validate
method.
from django-adapters.
As I already mentioned in #27, I really dislike how accessing form.errors
in Django currently triggers a full validation (or clean).
I agree that separating cleaners and validators makes sense but I think it would be ok to have them both subclass from the same base class and dynamically detect if they overrode clean()
or not.
from django-adapters.
Related Issues (20)
- Consider "Representation" naming. HOT 1
- Serialization and rendering HOT 14
- Add a license HOT 1
- Research existing attempts to do mirrored form rendering HOT 6
- Research input/output prior art HOT 3
- Prototype validation tree HOT 2
- Prototype top and second level APIs HOT 2
- Expand on "auxiliary" data like current request or user HOT 1
- Look at schematics HOT 3
- Corporate sponsoring, crowdfounding HOT 6
- "Dynamic" schemas HOT 2
- Do a Retrospective HOT 1
- Consider renaming to python-adapters, have adapters.django HOT 1
- Create tutorial from scratch ? HOT 3
- Look at react-jsonschema-form HOT 2
- Weekly hangout ! HOT 2
- Question about the adapters pattern HOT 1
- Is everything an adapter ? HOT 1
- Change repository description ?
- Look at glom
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 django-adapters.