Calculation parser ignores xlink:arcrole, keeps only the first of two arcs with different weights, and accepts a missing or zero weight
Issue Type
- [ ] Data Quality Issue (incorrect financial values, missing data)
- [x] XBRL Parsing Issue (statement rendering, concept mapping)
- [ ] Filing Access Issue (download failures, attachment problems)
- [ ] Performance Issue (slow operations, memory problems)
- [ ] Compatibility Issue (platform/dependency conflicts)
- [ ] Documentation Issue (unclear instructions, missing examples)
Environment
EdgarTools Version: main@2323d732 (reports 5.62.0); the same output on v5.62.0 (5068cc54)
Python Version: 3.14
Operating System: Windows
Bug Description
What you expected to happen:
Following the XBRL standard (Calculations 1.1 §4.1 and §4.2; XBRL 2.1 §5.2.5.2.1): only the summation-item arcroles build calculations, and the 2003 and 2023 summation-item networks are kept and checked separately. A second relationship with the same endpoints within one calculation is reported (calc11e:duplicateCalculationRelationships) rather than dropped. The weight attribute is required and non-zero.
What actually happened:
CalculationParser._collect_relationships (edgar/xbrl/parsers/calculation.py, lines 103-145) reads every calculationArc without checking xlink:arcrole. It keeps the first arc per (role, from, to) (lines 134-138) and drops later ones without notice, even when their weight differs. _parse_weight_attribute (lines 147-152) turns a missing or unparseable weight into 1.0 and accepts 0. CalculationArc (edgar/xbrl/models.py, lines 354-366) stores no arcrole, so a caller cannot tell XBRL 2.1 semantics from Calculations 1.1.
In the reproduction below:
- a 2003 summation-item arc OI to Revenues and a 2023 arc OI to CostOfRevenue in one role give one tree holding both;
- an arc with arcrole
http://example.com/arcrole/otheris kept as a summation; weight="0"is kept as 0.0, and a missing weight becomes 1.0;- two arcs with the same from and to and opposite weights keep only the first, so reversing their order reverses the returned weight.
Error message (if any):
None. The output is below.
Reproduction
Company/Ticker: Not applicable (minimal linkbases built in the code) Time Period: Not applicable Relevant Forms: Not applicable
Minimal code to reproduce:
from edgar import set_identity
set_identity("Your Name [email protected]")
from edgar.xbrl.parsers.calculation import CalculationParser
A03 = "http://www.xbrl.org/2003/arcrole/summation-item"
A23 = "https://xbrl.org/2023/arcrole/summation-item"
OTH = "http://example.com/arcrole/other"
def tree(arcs):
locs = "".join(f'<link:loc xlink:type="locator" xlink:label="{c}" xlink:href="x.xsd#us-gaap_{c}"/>'
for c in ["OI", "Revenues", "CostOfRevenue", "Other"])
body = "".join(f'<link:calculationArc xlink:type="arc" xlink:arcrole="{r}" xlink:from="OI" xlink:to="{t}"{w}/>'
for r, t, w in arcs)
xml = ('<link:linkbase xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink">'
f'<link:calculationLink xlink:type="extended" xlink:role="http://x/role/IS">{locs}{body}'
'</link:calculationLink></link:linkbase>')
trees = {}
CalculationParser({}, trees, {}, {}).parse_calculation_content(xml)
return [(a.parent_id, a.child_id, a.weight) for a in trees["http://x/role/IS"].all_arcs]
print("2003 + 2023 arcroles in one role:", tree([(A03, "Revenues", ' weight="1"'), (A23, "CostOfRevenue", ' weight="-1"')]))
print("foreign arcrole:", tree([(OTH, "Other", ' weight="1"')]))
print("weight='0':", tree([(A23, "Other", ' weight="0"')]))
print("weight missing:", tree([(A23, "Other", "")]))
print("same from/to, +1 then -1:", tree([(A23, "Revenues", ' weight="1"'), (A23, "Revenues", ' weight="-1"')]))
print("same from/to, -1 then +1:", tree([(A23, "Revenues", ' weight="-1"'), (A23, "Revenues", ' weight="1"')]))
print("CalculationArc fields:", list(__import__("edgar.xbrl.models", fromlist=["x"]).CalculationArc.model_fields))
Output on main@2323d732 (identical on v5.62.0):
2003 + 2023 arcroles in one role: [('us-gaap_OI', 'us-gaap_Revenues', 1.0), ('us-gaap_OI', 'us-gaap_CostOfRevenue', -1.0)]
foreign arcrole: [('us-gaap_OI', 'us-gaap_Other', 1.0)]
weight='0': [('us-gaap_OI', 'us-gaap_Other', 0.0)]
weight missing: [('us-gaap_OI', 'us-gaap_Other', 1.0)]
same from/to, +1 then -1: [('us-gaap_OI', 'us-gaap_Revenues', 1.0)]
same from/to, -1 then +1: [('us-gaap_OI', 'us-gaap_Revenues', -1.0)]
CalculationArc fields: ['parent_id', 'child_id', 'weight', 'order']
Additional Context
Mixed or foreign arcroles merge into one calculation, and a conflicting weight disappears unseen. This is outside current SEC practice: of 55 calculation linkbases checked locally, 42 use the 2023 arcrole and 13 the 2003 one, none mixes them, none has use="prohibited", 3 have priority attributes, and every weight is +1 or -1. Low priority. Prohibition and priority handling across the linkbases is a separate matter, not covered here.
Related: #1184, #1238 (both closed; earlier fixes to how calculation relationships are collected, not this behaviour).
This issue will be handled using EdgarTools' systematic issue resolution workflow. A reproduction test will be created to verify the fix.
@dgunning, here is our current thinking on the root cause, proposed behavior, and coordination with other issues.
Root Cause:
The calculation parser drops arcroles and deduplicates by endpoints before comparing weights, merging distinct networks and retaining the first conflicting relationship. It also invents a weight of +1 for missing or malformed input; the examples establish parser defects without proving a wrong issuer amount.
Proposed Behavior:
Preserve calculation arcroles in separate networks and retain each declared exact decimal weight. Diagnose missing, zero or unusable weights and conflicting relationships, making the affected total unavailable for evaluation while keeping other filing data usable. Retain custom arcroles for inspection outside ordinary sums, and require explicit network selection where a role is ambiguous. This repairs extraction and safe consumption without claiming a complete calculation validator.
Coordination:
Keep a separate PR after #1736, so priority/prohibition resolution precedes calculation eligibility and duplicate checks. Coordinate the shared model with #1758, preserve the landed PR #1261 and PR #1792 controls, and keep #1731 independent.
Below, please find the full design document. Please let me know your thoughts.
Brian
Attachment: design-public.md, Preserve calculation arcroles and reject invented contribution weights.
AI assistance: Codex; GPT-6.1 Sol (High) performed current-main scouting, reproduction and final writing; GPT-6 Astra (Max) researched the parser, consumers and XBRL specifications, designed the approach and independently reviewed its preservation of financial meaning.
Reopening: #1900 fixed the arcrole half (only summation-item arcs build calculations, deduplicated per arcrole). Two parts are still open: arcs in one network with the same endpoints and different weights still keep the first one silently, and a missing or zero weight still reads as 1.0.