Forum Discussion
FICO
5 years agoCommunity Manager
Issue with scenario attachments; attachment not found
Hello - looking for advice/help related to an issue with scenario attachments. we are using python to create several excel workbook files, which contain model input data. we have a set of strings (i.e. setA), and each element of setA should have a corresponding excel file. then, we iterate over setA and use insightputscenattach to upload each attachment.
we are finding that insightputscenattach fails (consistently) for one of the files. in mosel, we use getfsize to check to see if the file exist (e.g. has a non-0 size).
from python, we can read the file and we see that the file exists, has data, and therefore the size is not 0.
Bottom line: python is indicating the the files/attachments are fine (exist, and have a non-0 size). mosel is indicating that one of the files/attachments does not exist. We are unable to diagnose the issue, and thus unable to resolve the issue with the attachment.
Gary
18 Replies
- FICOCommunity Manager
Right now, our hypothesis is that on Windows, you get a zero file size in Mosel, because the Python component that created the file didn't properly close the file handle or a third party tool like a virus scanner has an open file handle on that file. In a future version of Mosel (probably the next release), getfsize will use a different Windows API routine to determine the file size, and we hope that this will solve the odd behavior with respect to the zero file size.
Can you confirm that getfsize returns 0 or does it return -1 ?
What error message do you get, when you try to upload the attachment with the "zero" file size?
- FICOCommunity Manager
PS:
Since you are the "getfsize > 0" check to detect whether the file exists or not, I would recommend to explicitly check whether the file exists, instead of checking its size (see code snippet below).
However, you are of course right that the zero file size is odd, and we hope that in the next release, the new version of getfsize will return a non-zero value in your situation. The behavior that you observe is unexpected, and it indicates an unexpected behavior of the Windows API routines that we used previously.
(!@doc. @descr Check if a regular file or folder exists. @param filename The file name to test. @return True if the regular file or folder exists. !) public function fexists(filename: text): boolean declarations status = getfstat(filename) end-declarations returned := status <> 0 and bittest(status, SYS_TYP) <> SYS_OTH end-function - FICOCommunity ManagerThanks for the follow-up, and for sharing your hypothesis. To answer your questions: 1. getfsize is returning 0 (not -1); which I interpreted to mean that the file is found but that the size is determined to be 0 (e.g. an empty file) 2. error message is as follows: “Error downloading attachment for market 110A” * Which is generated by code shown below (since insightattachstatus is not OK) if insightattachstatus <> INSIGHT_ATTACH_OK then writeln("Error downloading attachment for market "+ms)
- FICOCommunity Manager
Hi,
in the first message you wrote that the failure occurs when you try to upload the file with the zero file size.
"we are finding that insightputscenattach fails (consistently) for one of the files"
but in your previous message, you show the code snippet for downloading an attachment. When you call the function insightputscenattach for the 110A file to upload it to Insight, the function should write an error message to the error stream of your application, if something unexpected happens. I need to know what kind of error you see in the log file, when you try to upload that file, such that I can forward that info to the component developer.
My understanding is, that you used the file size check, to make the decision whether you want to upload the file or not. But in your case, getfsize returns zero, so that check doesn't work, and the file doesn't get uploaded. You need to replace your file size check with the fexists function that I shared in my previous post, such that the file gets uploaded, even when getfsize would return a zero file size.
Regards
- FICOCommunity Manager
Simply replace the file size check, with the existence check:
(!@doc. @descr Check if a regular file or folder exists. @param filename The file name to test. @return True if the regular file or folder exists. !) public function fexists(filename: text): boolean declarations status = getfstat(filename) end-declarations returned := status <> 0 and bittest(status, SYS_TYP) <> SYS_OTH end-function procedure set_attachment(filename: string, tags: list of string) if fexists(filename) then insightputscenattach(filename) if insightattachstatus=INSIGHT_ATTACH_OK then insightsetscenattachtags(filename,tags) writeln("Attachment "+filename+" added to the scenario.") else writeln("Error adding attachment "+filename) exit(1) end-if else writeln("Error adding attachment "+filename) writeln(" Filesize = 0 for "+filename) end-if end-procedure - FICOCommunity ManagerJohannes, thanks for the continued support on this item. I am cc’ing Kellington as he worked with us last Friday to trouble-shoot this issue. What we found (as I recall) is that all the expected files (excel workbook files) were in the working directory during executions. And, all these files had a non-0 size. Thus, it seems like there should not be an issue related to the scenario attachments. I can include code to skip any file that appears to have size=0, and this will avoid a run-time failure. But, this means that we are still not able to process one of the attachments. Thus, I am looking for a resolution that allows me to process the scenario attachment. Gary
- FICOCommunity Manager
I recall that I was asked to provide the status code from insight when the attachment issue occurs. I printed insightattachstatus and found that insightattachstatus=0.
Gary
- FICOCommunity Manager
> I printed insightattachstatus and found that insightattachstatus=0.
Please note that INSIGHT_ATTACH_OK = 0. If insightattachstatus = 0, after calling insightputscenattach, this actually means that the attachment upload was successful.
> I can include code to skip any file that appears to have size=0, and this will avoid a run-time failure.
We need to explicitly create that run-time failure such that we see the error message that mminsight writes to the log file and such that we see the value of You need to
- either temporarily remove the code "to skip any file that appears to have size=0"
- or try the code that I provided below, i.e., replace the code "to skip any file that appears to have size=0" by fexists.
In case 1, we would get the run-time error, and we would see mminsight’s error message, that we need to understand the issue.
In case 2, I would also expect that fexists would return true for the "size=0" file, i.e., we would also get the run-time error.
So in either of the cases, we should get the mminsight error message, that we can forward to the developer.
(!@doc. @descr Check if a regular file or folder exists. @param filename The file name to test. @return True if the regular file or folder exists. !) public function fexists(filename: text): boolean declarations status = getfstat(filename) end-declarations returned := status <> 0 and bittest(status, SYS_TYP) <> SYS_OTH end-function procedure set_attachment(filename: string, tags: list of string) if fexists(filename) then insightputscenattach(filename) if insightattachstatus=INSIGHT_ATTACH_OK then insightsetscenattachtags(filename,tags) writeln("Attachment "+filename+" added to the scenario.") else writeln("Error adding attachment ",filename," (Status: ",insightattachstatus,")") exit(1) end-if else writeln("Error adding attachment "+filename) writeln(" Filesize = "+getfsize(filename)) end-if end-procedure
Related Content
Related Content
- 11Views0likes2Comments
