jazzband / jsonmodels

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.
http://jsonmodels.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
334 stars 51 forks source link

Optionally disable validators for fields. #122

Closed LaserPhaser closed 5 years ago

LaserPhaser commented 6 years ago

JsonModels are heavily used in testing. And for testing purposes we need to be able to disable type validation in process of filling model with data. This why I suggest to add extra option to be able to disable validation for fields. By default validation is on, it will not break current behavior.

LaserPhaser commented 6 years ago

@beregond Please take a look, and share your thoughts

beregond commented 5 years ago

@ArseniyAntonov Hi, yes, that use case is interesting, but before that would go into the source code I'd like to know it more - so the question is why is validation in the way in tests? I mean if you load data from whatever source - you should simply change data source or definition and that would solve it (in my opition) - so where is the real problem with that? :)

LaserPhaser commented 5 years ago

@beregond Actually Dataclasses in https://docs.python.org/3/library/dataclasses.html fixed our problem, so there are no any reasons for this PR.

We've used jsonmodel for requests also, and for creating "wrong" requests for testing purposes we've tried to set wrong types, and we've got validation error from jsonmodel. So this patch could optionally disable validation for such things. But for now, we are using dataclasses for requests.

class Test(Model):
    x = IntField()

test = Test()
test.x = 'String instead of integer' # here we will got validation error from jsonmodels
beregond commented 5 years ago

@ArseniyAntonov ok, so I'm closing this one, thanks for the info!