-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix(MR-16): Use cache for FileField and ImageField #17
Conversation
87f4e08
to
f28e90d
Compare
a8fdaaa
to
c7bd9bc
Compare
Previously in Also added handy dandy tests readme to outline all the mutations that should be covered in test cases. 🤞 That this works better because |
c24bcc8
to
5dc8bde
Compare
|
586a3cd
to
4d311c1
Compare
|
||
if initial_value != new_value: | ||
changed_data[name] = [initial_value, new_value] | ||
if add: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change_data for add and change_data for change could be refactors into helper methods to make this easier to read. Perhaps create a utils file for these Or add them to the existing one.
This would also also for better unit testing
|
||
# Should have cleared cache | ||
for key in CACHE_KEYS.values(): | ||
self.assertIsNone(cache.get(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe 🤔 create a _assert helper method for this. It's required in most tests, but... it's bad practice to have any assert which is not explicit in the test func body.
So this took a very long time to get to. Here's the previous history #16. This is related to #8
That worked nicely for ManyToManyField but not for the ImageField or FileField.
This MR tries caching (which works for FileField and ImageField, but not ManyToManyField).... thus a combined solution is used. Cache is used primarily, but for any m2m/generic relation fields data it looked up from request.POST (sent via hidden embedded form) and saved the related models.
Note: Had to bypass
_save_related
andsave_m2m
but calls the underlaying functionsTests have been added for ManyToMany, File, and Image fields and caching