Possible side effect of fix to #482
Issue Type
- [ ] Data Quality Issue (incorrect financial values, missing data)
- [ ] 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: 4.27.0 **Python Version: 3.13.9 **Operating System:macOS
Bug Description
What you expected to happen: Fix to #482 worked. But now I get this error on almost every filing: Error extracting footnotes: cannot access local variable 'undefined_footnotes' where it is not associated with a value I tracked it down to this call: xbrl_data = filing.xbrl() Not sure this is an error message that should be going to console - better at debug level since there's nothing I can do about it and it's not even clear to the caller what it's all about or where it's coming from What actually happened: A clear description of what went wrong.
Error message (if any):
Error extracting footnotes: cannot access local variable 'undefined_footnotes' where it is not associated with a value
Reproduction
Almost any company and year, but for certain you can use ABT any year from 2015 on. Minimal code to reproduce:
xbrl_data = filing.xbrl()
Additional Context
Add any other context about the problem here. Screenshots, related issues, etc.
This issue will be handled using EdgarTools' systematic issue resolution workflow. A reproduction test will be created to verify the fix.
Classification: HIGH Priority (P1) - Regression from #482
Thank you for reporting this! I've reproduced the issue and identified the root cause.
Investigation Results (2025-11-10)
✅ Reproduced with ABT 2015 10-K filing:
import edgar
company = edgar.Company('ABT')
filings = company.get_filings(form='10-K').filter(filing_date='2015-01-01:2015-12-31')
xbrl_data = filings[0].xbrl()
# ✅ XBRL loads successfully
# ❌ Error: "Error extracting footnotes: cannot access local variable 'undefined_footnotes'
# where it is not associated with a value"
Root Cause
This is a regression introduced in the fix for #482. The bug is a simple variable scoping issue:
File: edgar/xbrl/parsers/instance.py
Problem:
- Line 549:
undefined_footnotes = set()is declared INSIDE thefor footnote_link in root.findall(...)loop - Line 573:
if undefined_footnotes:tries to reference it OUTSIDE that loop - When there are NO
footnoteLinkelements, the variable is never defined →UnboundLocalError - This exception is caught at line 578 and logged as a warning
Code snippet:
# Line 511
for footnote_link in root.findall('.//{http://www.xbrl.org/2003/linkbase}footnoteLink'):
# ...
undefined_footnotes = set() # ❌ Declared inside loop (line 549)
# ...
# Line 573 - OUTSIDE the loop
if undefined_footnotes: # ❌ References variable that may not exist
log.debug(f"{len(undefined_footnotes)} footnote arc references could not be resolved")
Analysis
Severity: HIGH (P1) - Regression, but not critical Impact:
- ❌ Annoying warning spam on almost every filing
- ❌ Users see confusing error messages they can't fix
- ✅ Functionality not broken (XBRL still loads successfully)
- ✅ Exception is caught, doesn't crash
Why Not Critical (P0):
- XBRL parsing still works correctly
- Only affects user experience (error messages), not data accuracy
- No functional regression
Fix
Extremely simple - move one line:
# Line 507 (add here, before the loop)
undefined_footnotes = set() # ✅ Declare before loop
# Line 511
for footnote_link in root.findall('.//{http://www.xbrl.org/2003/linkbase}footnoteLink'):
# Now safe to use undefined_footnotes here
# ...
Estimated effort: XS (0.2 days / 1 hour)
- Change: 1 line moved
- Testing: Verify no warnings on ABT 2015, verify existing tests pass
- Regression test: Add test case for filings without footnoteLink elements
Release Planning
Option 1: Point release v4.27.1 (if bundled with #487)
- If we're doing a point release for #487 error handling
- Bundle this trivial fix to eliminate user-facing regression
Option 2: Minor release v4.28.0
- Include with other UX improvements (#482, #487)
- Acceptable since functionality isn't broken
Recommendation: v4.27.1 point release
- This is a user-visible regression from recent release
- Fix is trivial (1 line)
- Good to eliminate error spam quickly
Tracking
- Beads Issue: edgartools-wpy (P1 high priority, regression)
- Labels:
bug,regression,priority:high - Timeline: Can fix in <1 hour
User Feedback
You're absolutely right about the error level:
"Not sure this is an error message that should be going to console - better at debug level since there's nothing I can do about it and it's not even clear to the caller what it's all about or where it's coming from"
The warning should be at DEBUG level, but with this fix, the warning won't appear at all for files without footnoteLink elements, which is the correct behavior.
Summary: Simple regression from #482 fix. Variable scoping issue causes warning spam. Trivial fix (move 1 line). Will include in upcoming release (v4.27.1 or v4.28.0). Thank you for the detailed report!
Fixed in Release 4.27.1