Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when attempting to save serializer if data is not valid. #2098

Closed
j0hnsmith opened this issue Nov 19, 2014 · 4 comments
Closed

Comments

@j0hnsmith
Copy link

I'm seeing some unexpected behaviour in v3

In [23]: MyModel.objects.count()
Out[23]: 0

In [24]: s = MyModelSerializer(data={'foo': 'bar'})

In [25]: s.is_valid()
Out[25]: False

In [26]: s.errors
Out[26]: ReturnDict([('baz', [u'This field is required.'])])

In [27]: s.save()
Out[27]: <MyModel: MyModel object>

In [28]: MyModel.objects.count()
Out[28]: 1

Not necessarily a problem but perhaps worth a note in the docs.

@j0hnsmith
Copy link
Author

I just found s.is_valid(raise_exception=True)

@tomchristie tomchristie changed the title object created when serializer.is_valid() is False Raise error when attempting to save serializer if data is not valid. Nov 20, 2014
@tomchristie
Copy link
Member

Retitled slightly.

@tomchristie tomchristie added this to the 3.1 Release milestone Nov 20, 2014
@phalt
Copy link
Contributor

phalt commented Dec 1, 2014

Should the default on this be def is_valid(self, raise_exception=True): ?

What's the rational for having raise_exception=False as the default?

@tomchristie
Copy link
Member

Should the default on this be is_valid(self, raise_exception=True)

I could go either way, but somehow it feels like having it raise the exception should be the explicit case.

This ticket for ".save() should raise an error if the data was not validated" still stands on it's own of course.

@tomchristie tomchristie modified the milestones: 3.1 Release, 3.0.1 Release Dec 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants