apps-android-commons
apps-android-commons copied to clipboard
[Bug]: "copy the wikitext to the clipboard" produces different results depending on timing
Summary
Pressing the button copy the wikitext to the clipboard produces a different result depending if the upload is still in progress (wrong result), or whether the upload has finished (correct result).
Steps to reproduce
- have a slow network connection
- add new picture, fill metadata and submit
- while the picture is still uploading (i.e. a progress bar is being shown), click on the
copy the wikitext to the clipboardbutton and paste the result somewhere - wait until the upload finishes
- click on the
copy the wikitext to the clipboardbutton again and paste the result somewhere
Expected behaviour
the first and second value copied are the same.
Actual behaviour
The first and second results differ. For example, for this file: https://commons.wikimedia.org/wiki/File:Knafel%C4%8Deva_markacija_na_odrezanoj_grani,_Prvi%C4%87.jpg the first copy/paste produces:
[[Knafelčeva markacija na odrezanoj grani, Prvić.jpg|thumb|]]
(which is wrong) while the second copy/paste produces (correct!):
[[File:Knafelčeva markacija na odrezanoj grani, Prvić.jpg|thumb|]]
i.e. the first one misses File: (which then makes problems when one pastes it to the app that expects standard commons format, like e.g. EveryDoor). Especially annoying when the mobile internet is slow, as one is forced to either wait a long time, or manually fix every image name.
Device name
Huawei P30Pro
Android version
Android 10 (EMUI 12)
Commons app version
4.1.0 (latest f-droid)
Device logs
No response
Screen-shots
https://github.com/commons-app/apps-android-commons/assets/156656/71de16af-e770-4aeb-961f-eadd9d19228d
Would you like to work on the issue?
None
hello @nicolas-raoul, i am new to the project and exploring the project. Since it is a good-first-issue, can i give it a try?
@Kshitiz-Mhto It is yours, thanks! Please let us know about your progress every few days. 🙂
actually my exams are ongoing ryt now, so i am giveing as much as free time i have on this. so my response might be delay hope you understand.
i did find this code that casing the issue, i m workng on it. thanks you
file -> fr.free.nrw.commons.media.MediaDetailFragment
@Kshitiz-Mhto Sure no worries, please focus on your exams, letting us know every 2 weeks is fine. :-)
@Kshitiz-Mhto are you still working on this? @nicolas-raoul Can I please give this a try? This is my first open source contribution. I will try my best and I think I would be able to finish this within two weeks 😄
@TaiHaDev How about #5263? :-)
Hi @nicolas-raoul, I had a look at the issue but I couldn't reproduce but I found an interesting one #5212 that I can reproduce the bug . Can I give it a try?😁 I will regularly update my progress. Thank you!
@TaiHaDev Sure! Please comment there, as I can't assign you unless you comment. Thanks! :-)
my exam r over now, i m all good to go now, i will finish this as soon as i can. thank u!
Any luck @Kshitiz-Mhto ?
Hello! I'm new to the open source community and exploring the project. I saw this is a good first issue. Could I give it a try?
Hello! I'm new to the Open Source Contribution
@axelthepony27 It is yours, please let us know about your progress every week or so, thanks! 🙂
@annuk123 How about https://github.com/commons-app/apps-android-commons/issues/5194 for instance? 🙂
@nicolas-raoul Thanks! I forked the repo and cloned it to my locale, but the file fr.free.nrw.commons.media.MediaDetailFragment appears to have an import that doesn't exist. Is this a problem of mine, or do you know what else could be causing this?
@axelthepony27 And what happens when you try to compile? Do you get some error, or does it just work?
For me, GitHub workflow seems to compile latest main just fine, e.g. https://github.com/mnalis/apps-android-commons/actions/runs/7346949892/job/20002559077
@mnalis When I try to build, I get this error. Perhaps I missed a step in the configuration? Is there something else I should do? I followed the steps described in the quick guide verbatim (at least to my knowledge).
@axelthepony27 well, I don't really know (I don't even have local Android SDK installed - I just use GitHub to build it).
But:
- the "failed to find Platform SDK with path" (which is the real error) seems to me unrelated to the originally reported error ("missing fr.free.nrw.commons.BuildConfig", which seems to be a red herring)
- it seems related to your build toolkit, not to Commons app itself. Have you been successfully building any other Android projects on that setup?
- my first guess would be that the "platforms;android-33" part of the error might indicate you need to download that correct platform? e.g. via
menu > Tools > SDK Manager? As shown in screenshot here - if that doesn't help, I'd try searching the web for the web for similar errors
@mnalis Thanks! Indeed, the problem was solved by installing the correct SDK. I'll get to work on the issue now, it does appear to concern to the fragment of code that @Kshitiz-Mhto mentioned.
Doing some tests, I found out that the "description" metadata also changes if copied during upload. Do we know if this is expected, or is it also part of the issue?
In the following SS, the first line of text was copied during upload, and the second one once it was done. We can noties that, indeed, the File: substring is missing, but there are also some dangling {} and en|1= that aren't present in the expected result.
Great finding!
Ideally File: should be present even when copied during upload.
The second line's syntax is the right one.
@annuk123 How about #5194 for instance? 🙂
Thanks 😇
@annuk123 That one got taken quickly, but how about https://github.com/commons-app/apps-android-commons/issues/5413 ?
Well, doing some tests, I determined the problem lies on the media.getFilename() and media.getFallbackDescription() methods. Something happens between when the upload is in progress and when it is done that changes the outputs of those methods. I, however, was unable to locate where, as those attributes come from the file Media.kt, and don't have explicit getters. Does anyone have any idea where the problem might originate? Perhaps on the code that manages the upload of files.
@axelthepony27 perhaps you can add the debug code around places where this gets called to get more precise idea when and where exactly the value changes? That should be instructional to finding the cause of the issue (and thus, the fix).
@mnalis Thanks, I'll try that. I went on vacation for a couple of weeks, but I'll retake the issue this week
Doing some more tests, I noticed that, while an image is still uploading, the "Description" field presents the text in the wrong format, like this:
However, after the image has finished uploading, the description text is correct:
This leads me to believe that the error doesn't lie in the copy method itself, onCopyWikicodeClicked(), as originally thought, but rather on something else: perhaps the the code that generates the text fields on the image's card in the first place. Does anyone know where that happens, so that I could have a better-guided debugging? I can't seem to find where it happends, or another good place to look for the bug.
Well, I found the bit of code that formats the "Description" part only. It seems to happen during upload. The upload process formats the filename and description of an upload differently than when an upload is done. I think after an upload has finished, the details panel pulls the filename and description from some other place. However, I'm unable to find where exactly. In any case, what might be happening could be fixed by one of two ways:
- Find when and from where the filename and description fields pull the text, and agree them so that they pull the text from only one place (the correct one). I still, however, would need to find when and where it happens exactly.
- Agree the formats both during upload and when the upload is done. This, however, doesn't seem like a good solution, as the description of method
formatDescriptions()in classContribution.ktsays it "Formats the list of descriptions into the format Commons requires for uploads."
Testing it, this method definitively is where the "wrong" format takes place:
I would like a little more guidance on how to proceed, if anyone could lend me a hand.
Hi @nicolas-raoul , I just started to look for issues so that I can contribute, since it is a good first issue can i give it a try
Hi, @nicolas-raoul @mnalis. Just following up on this, did you have the chance to check out my questions?