-
Notifications
You must be signed in to change notification settings - Fork 132
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
Submission attachments list is not updated correctly after replacing an old image/file with a new one. #1696
Comments
The current implementation when editing submissions with new attachment files does not delete the old attachment, but creates a new attachment to the same submission alongside the old attachment files. This could be helpful when keeping track of the submission history, however, as we never delete attachment files, this approach could fill up our storage unnecessarily. @ukanga @pld @ivermac @JohnMwashuma @lincmba is there a different approach we could use, as in this instance when one edits a submission with a new media file? |
since this data is going in s3, and it's the way we're doing it now, I'm not particularly concerned about storage space. If we can ignore attachments that are connected to submissions that are marked as deleted, would that be sufficient to address this error? |
So i found a way of filtering the attachments list from the submission api endpoint response. The response has the list of attachment fields with the attachment names. I used these names to filter the attachments. |
Does this issue affect exports or attachment downloads?
… On Oct 4, 2019, at 4:14 AM, John Kirigha Mwashuma ***@***.***> wrote:
So i found a way of filtering the attachments list from the submission api endpoint response. The response has the list of attachment fields with the attachment names. I used these names to filter the attachments.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1696?email_source=notifications&email_token=AAAMMETCIHT7K3URGIMLQILQM33MZA5CNFSM4I4V52AKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAK3WQA#issuecomment-538295104>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAAMMEQ4FFTADRCHVFK74SDQM33MZANCNFSM4I4V52AA>.
|
yes it affects attachments, all attachments are downloaded even the ones that had been replaced. |
sounds like we need a general fix then that only surfaces attachments to instance that do have |
…ill populate deleted_at field for attachments. Fixes #1696
…ill populate deleted_at field for attachments. Fixes #1696
…ill populate deleted_at field for attachments. Fixes #1696
…ill populate deleted_at field for attachments. Fixes #1696
We may need to rethink this again - it will be more like we should not expose in any way the attachments that have been replaced. Hence the files/attachments endpoint should not expose these records at all. I like the idea of |
Yes agree, that's how we use the |
…ill populate deleted_at field for attachments. Fixes #1696
…ill populate deleted_at field for attachments. Fixes #1696
QA for this issue is proving to be abit tricky. After discussions with @DavisRayM and @ivermac , we discussed catching this update, while saving the attachments to the instance on this file onadata/onadata/libs/utils/logger_tools.py Lines 217 to 244 in 3faabd3
At this point we could check the existing attachments for that instance and compare with the list of media files received from the update request and call the soft_delete action to delete the replaced attachments. CC: @pld @ukanga |
how would we compare with the list of media files received? is this that if we replace an attachment for an instance, we'd only want to delete the existing attachment for that same field? in that case is the check that we see if there's an existing attachment for the field we're replacing the attachment in, and delete that existing one if there is? I'm trying to avoid a loop over all attachments if know specifically what attachments are relevant. |
We would be deleting existing attachments to an instance that have been replaced (i.e if they are no longer in the media files received with that instance).
yes, this is what we had in mind. onadata/onadata/libs/utils/logger_tools.py Lines 354 to 359 in 3faabd3
We can then identify the attachments that have been replaced and soft_delete those.
True. Alternatively, we could use generator expressions as opposed to list comprehensions to filter these |
This sounds good, let's pursue your final comment below and try to do this without a loop.
|
…ill populate deleted_at field for attachments. Fixes #1696
Create soft_delete action that will populate deleted_at field for attachments. Fixes #1696 Call soft_delete action when replacing attachments
LGTM 🙂 |
@WNjihia I think you want this comment and |
Create soft_delete action that will populate deleted_at field for attachments. Fixes #1696 Call soft_delete action when replacing attachments
Environment (local, stage, preview, production)
All
Expected behaviour
When an image/file in a submission is replaced, the old image/file should be replaced with the new one and deleted from the attachments list.
Actual behaviour
The old image/file is replaced successfully but the old image/file is still retained in the attachments list.
Steps to reproduce the behaviour
Use Enketo to edit a submission that has an attachment. Check the attachments for that submission and you will notice the previous attachment is still available.
Implementation plan
Blocking or related onadata issues
Aha! Link: https://ona.aha.io/features/PROD-213
The text was updated successfully, but these errors were encountered: