Giter VIP home page Giter VIP logo

Comments (7)

mjtamlyn avatar mjtamlyn commented on June 10, 2024 1

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.

LilyFoote avatar LilyFoote commented on June 10, 2024

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.

mjtamlyn avatar mjtamlyn commented on June 10, 2024

The problem is, if a "plain" validator depends on a cleaning one, then you need to mirror them all.

from django-adapters.

LilyFoote avatar LilyFoote commented on June 10, 2024

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.

LilyFoote avatar LilyFoote commented on June 10, 2024

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 Form.clean method only runs if all other validators pass. This is nicer than checking manually in Form.clean which fields have been successfully cleaned and which have failed validation.

from django-adapters.

LilyFoote avatar LilyFoote commented on June 10, 2024

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.

MoritzS avatar MoritzS commented on June 10, 2024

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)

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.