Skip to content
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

Troubleshooting XULE Script Execution Error with Arelle on Amazon Linux 2 #28

Open
pontsoleil opened this issue Mar 24, 2024 · 4 comments

Comments

@pontsoleil
Copy link

pontsoleil commented Mar 24, 2024

I'm evaluating the XULE plugin with Arelle on Amazon Linux 2, using Python 3.8. My script, successfully executed in XMLSpy 2024, aims to analyze hierarchical XBRL instances for journal entries, using dimensions to define journal headers, lines, and sub-account details. However, while compilation appears successful, running the script with --xule-run results in an error. The script calculates debit and credit travel expenses, showing promising results when tested elsewhere:

namespace cor=http://www.iso.org/awi21926_jisc

output TravelExpense

$DebitEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==true}.dimensions())
$CreditEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==false}.dimensions())
$TravelExpenses = set({covered @concept=cor:JISC04b_GL03_01 where $fact=='726'}.dimensions())
$totalDebitTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.dimensions() in $DebitEntries and $fact.dimensions() in $TravelExpenses}))
$totalCreditTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.dimensions() in $CreditEntries and $fact.dimensions() in $TravelExpenses}))

"The total travel expenses are Debit:{$totalDebitTravelExpenses} JPY Credit:{$totalCreditTravelExpenses} JPY"

Successful output in XMLSpy 2023:

Successfully executed XULE on JISCinstance.xbrl in 16ms
    [TravelExpense] The total travel expenses are Debit:28,096 JPY Credit:None JPY

On Arelle, compilation feedback is positive, but execution fails:

(arelle-env) [ec2-user Arelle]$ python arelleCmdLine.py --plugins xule --xule-compile /home/ec2-user/UADC/data/xule/travel_expense.xule --xule-rule-set /home/ec2-user/UADC/data/xule/travel_expense.zip
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Xule version: 3.0.23722 -
2024-03-24T14:02:47.357186: travel_expense.xule parse start
2024-03-24T14:02:47.932898: travel_expense.xule parse end. Took 0:00:00.575712
2024-03-24T14:02:47.933101: travel_expense.xule ast start
2024-03-24T14:02:47.933378: travel_expense.xule ast end. Took 0:00:00.000277
2024-03-24T14:02:47.933405: post parse start
2024-03-24T14:02:47.934987: post parse end. Took 0:00:00.001582
2024-03-24T14:02:47.936886: Parsing finished. Took 0:00:00.581420

(arelle-env) [ec2-user Arelle]$ python -m arelle.CntlrCmdLine --plugin xule --xule-run --xule-rule /home/ec2-user/UADC/data/xule/travel_expense.zip
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule
[info] Xule version: 3.0.23722 -
[xule:error] rule TravelExpense: 'all' -

(arelle-env) [ec2-user Arelle]$

Could you review my approach to ensure it's correct? I'm looking to refine this process before advancing to XINCE for trial balance reporting. Your insights on proceeding with this test would be greatly appreciated.

@pontsoleil
Copy link
Author

On MacOS, I attempted to run a XULE rule set against an XBRL instance using Arelle and encountered an error. Here's the command I used:

$ python arelleCmdLine.py --file /Users/pontsoleil/Documents/GitHub/UADC/data/instance/JISCinstance.xbrl --plugin ~/Arelle/plugins/xule --xule-run --xule-rule /Users/pontsoleil/Documents/GitHub/UADC/XULE/JISC/travel_expense.xulec

The XULE plugin activated successfully, and the XBRL instance loaded quickly. However, during the process, I encountered the following error:

$ python arelleCmdLine.py --file /Users/pontsoleil/Documents/GitHub/UADC/data/instance/JISCinstance.xbrl --plugin ~/Arelle/plugins/xule --xule-run --xule-rule /Users/pontsoleil/Documents/GitHub/UADC/XULE/JISC/travel_expense.xulec
[info] Activation of plug-in XBRL rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - /Users/pontsoleil/Arelle/plugins/xule 
[info] Xule version: 3.0.23722 - 
[info] loaded in 0.08 secs at 2024-03-24T19:35:10 - /Users/pontsoleil/Documents/GitHub/UADC/data/instance/JISCinstance.xbrl 
[xule:error] rule TravelExpense: unhashable type: 'dict' - JISCinstance.xbrl 

This suggests an issue within the TravelExpense rule in the .xulec file, potentially related to attempting to use a dictionary type in a context that requires hashable objects.

@pontsoleil
Copy link
Author

I've enhanced a method for processing IDs within XULE scripts, aimed at accurately calculating travel expenses. This technique capitalizes on the substring of an ID that corresponds to a contextRef attribute, linking directly to a dimension within the XML structure. Below is an XML snippet illustrating this association:

<context id="c-02">
    <entity>
        <identifier scheme="http://www.example.com">Example Co.</identifier>
        <segment>
            <xbrldi:typedMember dimension="cor:d_JISC03">
                <cor:_v>1</cor:_v>
            </xbrldi:typedMember>
            <xbrldi:typedMember dimension="cor:d_JISC04b">
                <cor:_v>1</cor:_v>
            </xbrldi:typedMember>
        </segment>
    </entity>
    <period>
        <instant>2023-10-31</instant>
    </period>
</context>
<cor:JISC04b_GL03_01 contextRef="c-02" id="adc.r_2.JISC04b_GL03_01">726</cor:JISC04b_GL03_01>
<cor:JISC04b_GL03_02 contextRef="c-02" id="adc.r_2.JISC04b_GL03_02">Travel expense</cor:JISC04b_GL03_02>
<cor:JISC04b_GL03_06 contextRef="c-02" id="adc.r_2.JISC04b_GL03_06">true</cor:JISC04b_GL03_06>
<cor:CC04w_01 contextRef="c-02" decimals="INF" id="adc.r_2.CC04w_01" unitRef="u-01">18572</cor:CC04w_01>

The script demonstrates an efficient dimension management approach by employing ID substrings, a technique overcoming prior limitations faced with dictionary-based dimension handling. The script's operations:

Refined XULE Script

namespace cor=http://www.iso.org/awi21926_jisc

output TravelExpense

/* Sets based on conditions matched by ID substrings */
$DebitEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==true}.id.substring(1,8))
$CreditEntries = set({covered @concept=cor:JISC04b_GL03_06 where $fact==false}.id.substring(1,8))
$TravelExpenses = set({covered @concept=cor:JISC04b_GL03_01 where $fact=='726'}.id.substring(1,8))

/* Totals calculation based on conditions */
$totalDebitTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.id.substring(1,8) in $DebitEntries and $fact.id.substring(1,8) in $TravelExpenses}))
$totalCreditTravelExpenses = sum(list({covered @cor:CC04w_01 where $fact.id.substring(1,8) in $CreditEntries and $fact.id.substring(1,8) in $TravelExpenses}))

/* Output statement for total expenses */
"The total travel expenses are Debit:{$totalDebitTravelExpenses} JPY Credit:{$totalCreditTravelExpenses} JPY"

Execution and Compilation

Utilizing Arelle and its XULE plugin on MacOS, the script underwent seamless compilation and execution.

Outcome

The script's execution verified its ability to compute total travel expenses.

Considerations for OIM-CSV

The application of this technique to OIM-CSV, which not explicitly contain ID values, remains to be clarified. The XBRL instance utilized was generated by Arelle from OIM-CSV input, highlighting the need for further investigation into the compatibility of this method with OIM-CSV formats.

@campbellpryde
Copy link
Contributor

campbellpryde commented Mar 25, 2024 via email

@campbellpryde
Copy link
Contributor

I have recreated the error and am looking at a fix for the dictionary match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants