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 issue where Set.delete_uploaded_files removes files it should not… #429
fix issue where Set.delete_uploaded_files removes files it should not… #429
Conversation
… during an update
…ectly computes that change on an update
I'm still not sure this is the complete fix as it is possible that an update causes compute fields to change and they will not appear in upload_fields, causing the file to not be deleted. My second commit fixes this problem however it causes some fields to be computed twice, any suggestion? |
Current coverage is 65.75% (diff: 30.00%)@@ master #429 diff @@
==========================================
Files 69 69
Lines 8912 8918 +6
Methods 0 0
Messages 0 0
Branches 1949 1950 +1
==========================================
+ Hits 5862 5864 +2
- Misses 2546 2549 +3
- Partials 504 505 +1
|
@@ -2141,24 +2148,23 @@ def delete_uploaded_files(self, upload_fields=None): | |||
oldname = record.get(fieldname, None) | |||
if not oldname: | |||
continue | |||
if upload_fields and fieldname in upload_fields and \ | |||
oldname == upload_fields[fieldname]: | |||
continue |
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.
@leonelcamara why changing this whole block of code to avoid a continue
?
@leonelcamara @mdipierro @niphlod can I start a discussion about computed fields before merging this? I would like to change the whole logic of how computed fields are computed during inserts/updates 'cause for example we still can't use them in callbacks (see emmett-framework/emmett#151 for example). May I produce a bigger PR including this fix? What do you think? |
The more streamlined the better
|
@niphlod what do you mean by streamlined? :) |
@gi0baro sure, I think we need to discuss computed fields, because although this PR fixes a problem it is not efficient. Fields with a compute should probably have a required_fields for instance. |
Streamlined as in "we know current has drawbacks and we'll think about fix
it once and for all" :-P
|
@leonelcamara @gi0baro this PR now has conflicts with the one that was merged. Can you please help resolve those? |
@leonelcamara @mdipierro I close this since is already fixed by #431 |
thanks! |
… during an update
The change I made differentiates between updates and deletes by taking advantage of upload_fields always being None in the case of deletes. If it is an update it only deletes the file if the field with it was updated and the new value is different.
See:
https://groups.google.com/forum/#!topic/web2py-developers/gwEr1cHQNAY