Closed hakamine closed 5 years ago
Log with extra info:
...
INFO 2017-09-13 16:05:23 transfer.py:388 Ready to start
INFO 2017-09-13 16:05:23 transfer.py:414 Approving ITEM@2429-24573.zip
INFO 2017-09-13 16:05:29 transfer.py:424 Found waiting transfer: ITEM@2429-24573.zip
INFO 2017-09-13 16:05:29 transfer.py:429 URL: http://127.0.0.1/api/transfer/approve/; Params: {u'username': 'autob
ot', u'directory': 'ITEM@2429-24573.zip', u'api_key': '<api-key>', u'type': u'dspace'};
INFO 2017-09-13 16:05:29 transfer.py:431 Response: <Response [500]>
INFO 2017-09-13 16:05:29 transfer.py:432 Response text: {"message": "Unable to find unapproved transfer directory.
", "error": true}
INFO 2017-09-13 16:05:29 transfer.py:398 Failed approve, try 1 of 3
INFO 2017-09-13 16:05:29 transfer.py:414 Approving ITEM@2429-24573.zip
INFO 2017-09-13 16:05:35 transfer.py:424 Found waiting transfer: ITEM@2429-24573.zip
INFO 2017-09-13 16:05:35 transfer.py:429 URL: http://127.0.0.1/api/transfer/approve/; Params: {u'username': 'autobot', u'directory': 'ITEM@2429-24573.zip', u'api_key': '<api-key>', u'type': u'dspace'};
INFO 2017-09-13 16:05:35 transfer.py:431 Response: <Response [500]>
INFO 2017-09-13 16:05:35 transfer.py:432 Response text: {"message": "Unable to find unapproved transfer directory.", "error": true}
INFO 2017-09-13 16:05:35 transfer.py:398 Failed approve, try 2 of 3
INFO 2017-09-13 16:05:35 transfer.py:414 Approving ITEM@2429-24573.zip
INFO 2017-09-13 16:05:41 transfer.py:424 Found waiting transfer: ITEM@2429-24573.zip
INFO 2017-09-13 16:05:41 transfer.py:429 URL: http://127.0.0.1/api/transfer/approve/; Params: {u'username': 'autobot', u'directory': 'ITEM@2429-24573.zip', u'api_key': '<api-key>', u'type': u'dspace'};
INFO 2017-09-13 16:05:42 transfer.py:431 Response: <Response [500]>
INFO 2017-09-13 16:05:42 transfer.py:432 Response text: {"message": "Unable to find unapproved transfer directory.", "error": true}
INFO 2017-09-13 16:05:42 transfer.py:398 Failed approve, try 3 of 3
WARNING 2017-09-13 16:05:42 transfer.py:400 Not approved
...
The API error "Unable to find unapproved transfer directory" comes from this code block: https://github.com/artefactual/archivematica/blob/stable/1.6.x/src/dashboard/src/components/api/views.py#L442-L474 . It looks for the corresponding job using the following ORM query:
job = models.Job.objects.filter(directory=db_transfer_path, currentstep='Awaiting decision')[0]
but this query failed producing an exception.
For some reason job.directory
is sometimes missing the ending slash, and when this happens the query fails.
For example in this case:
>>> from main import models
>>> job = models.Job.objects.filter(currentstep='Awaiting decision')[0]
>>> job.sipuuid
u'cd4833aa-fb38-4d80-be94-b0a8abdaafb1'
>>> job.directory
u'%sharedPath%watchedDirectories/activeTransfers/Dspace/ITEM@2429-24573.zip'
When trying to approve the transfer (using curl), got the same error:
curl -v --data "username=autobot&api_key=<api-key>&type=dspace&directory=ITEM@2429-24573.zip" "http://127.0.0.1/api/transfer/approve/"
...
{"message": "Unable to find unapproved transfer directory.", "error": true}
Tried adding the missing slash:
>>> job.directory
u'%sharedPath%watchedDirectories/activeTransfers/Dspace/ITEM@2429-24573.zip'
>>> job.directory = u'%sharedPath%watchedDirectories/activeTransfers/Dspace/ITEM@2429-24573.zip/'
>>> job.directory
u'%sharedPath%watchedDirectories/activeTransfers/Dspace/ITEM@2429-24573.zip/'
>>> job.save()
>>>
After this, the transfer could be approved:
artefactual@courtenay2:~$ curl -v --data "username=autobot&api_key=<api-key>&type=dspace&directory=ITEM@2429-24573.zip" "http://127.0.0.1/api/transfer/approve/"
...
{"message": "Approval successful.", "uuid": "cd4833aa-fb38-4d80-be94-b0a8abdaafb1"}
The problem does not happen with every transfer stated by the automation tools instance, but only sporadically, which makes it harder to troubleshoot.
This problem was caused by the 00_file_to_folder.py
pre-transfer script, that copies the zip file to a directory of the same name before approving the transfer (i.e., transfer is "started" as a file but then it is converted to a directory before the automation tools tries to "approve" it).
Copying the zip file to a directory in advance of running the automation script, and removing the 00_file_to_folder.py
script from the pre-transfers directory, prevents the problem to happen.
I found a way to reproduce this problem, and now can confirm that the problem is caused by the 00_file_to_folder.py pre-transfer script. What happens is roughly as follows:
If 3a. occurs before than 3b. then the transfer can be approved without failure If 3b. occurs before than 3a. then the problem occurs (the transfer will fail to approve), the reason being that the parameter containing the path information in the job object no longer matches the actual path of the DSpace file in the watched directory (because it was moved by the 00_file_to_folder script)
The 00_file_to_folder.py pre-transfer script is a "hack" used to allow other transformation scripts to run, which require transfer sources to be inside a directory. However as explained above, the execution order that it needs to work can't be guaranteed.
Work around:
Moving to: archivematica/issues#361
Sometimes automation tools fail to approve transfers, requiring manual intervention (i.e., approve manually in the dashboard). Log shows:
When this happens, the corresponding database entry does not update (running the automated transfer script again does not update it), so for the package that needed to be manually approved and had the ingest completed, unit_type is "transfer" and status remains blank, also uuid is blank :
It is not clear how to be able to reproduce this problem. (Error above occurred in the dev/dspace branch)