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

Full clean builtin #141

Merged
merged 1 commit into from
Sep 29, 2020
Merged

Full clean builtin #141

merged 1 commit into from
Sep 29, 2020

Conversation

sjamaan
Copy link
Contributor

@sjamaan sjamaan commented Aug 31, 2020

This implements #128 by calling full_clean in BinderModel's save() method.

At least, for Binder models this is the case.  All models managed by
Binder views should inherit from BinderModel, and if not, the user
should code validation error checking in _store().

In all our projects we use django-fullclean because being able to
accidentally save invalid models is a huge mind fuck.  Thus, it is
pointless to call full_clean() in our views, as it means we'll be
running potentially expensive validations twice.  For example,
relation fields check that the foreign relation exists, which requires
a query per relation field.

It is technically a breaking change, but for most projects this will
be a non-issue.  The test suite of Boekestijn passed except for one
test which was specifically for its User view, which uses a non-Binder
model.  This was relatively easy to convert to use a full_clean() in
its _store() method.
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2020

Codecov Report

Merging #141 into master will decrease coverage by 0.07%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #141      +/-   ##
==========================================
- Coverage   78.19%   78.12%   -0.08%     
==========================================
  Files          24       24              
  Lines        3252     3264      +12     
==========================================
+ Hits         2543     2550       +7     
- Misses        709      714       +5     
Impacted Files Coverage Δ
binder/views.py 84.42% <64.70%> (-0.35%) ⬇️
binder/models.py 79.09% <89.28%> (+0.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 659d0bf...b5ec096. Read the comment docs.

@sjamaan sjamaan force-pushed the full-clean-builtin branch from da93764 to b5ec096 Compare August 31, 2020 12:43
sjamaan pushed a commit that referenced this pull request Sep 1, 2020
This leverages our custom full_clean implementation (#141) in
combination with the LoadedValues mixin.  This allows us to know when
a value did not change and avoid validating the foreign key just
before save, because the foreign key was fine as it was stored, so it
cannot suddenly become invalid.

For complex models with many relations or which are saved a lot, this
makes a big difference, as the reduced number of queries can make
things quite a bit more efficient.
@daanvdk daanvdk merged commit 4f7cda3 into master Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants