Undefined References
Confiance : high
undefined-referencespython-errorsimport-failuresmodule-loadingcode-qualityruntime-errorsassistant-rhcritical-bugsnameerrorimporterrorattributeerrorproduction-failures
Programming errors where code references classes, functions, or variables that are never defined or properly imported, resulting in NameError, ImportError, or AttributeError exceptions at runtime. Particularly problematic in Python applications where import-time errors can cause complete module loading failures.
Common Patterns
Missing Import Statements
# Error: BaseRetriever referenced but never imported
class SparseRetriever(BaseRetriever): # NameError at class definition
pass
# Error: List and Document used in type hints without import
def process_documents(docs: List[Document]) -> List[Document]: # NameError
return docs
Incomplete Module Dependencies
# Error: date module referenced but not imported
def today_fr():
return date.today().strftime("%Y-%m-%d") # NameError: name 'date' is not defined
Package Structure Issues
# Error: Incorrect import path
from config import settings # Should be from src.rag.config
from pipeline import RAGPipeline # Module not in current path
Impact on Production Systems
In the assistant-rh system, undefined references caused:
- Complete module loading failures
- Immediate runtime crashes on function calls
- Broken entry points preventing application startup
- Cascade failures across dependent modules
Prevention Strategies
Static Analysis
- Use tools like
pylint,mypy, orpyflakesto catch undefined references - Implement pre-commit hooks for import validation
- Regular code review focusing on import statements
Testing Practices
- Import testing in CI/CD pipelines
- Module loading validation tests
- Smoke tests for all entry points
Development Workflow
- IDE configuration for import assistance
- Explicit import statements over wildcard imports
- Regular refactoring to maintain clean dependencies
Common in RAG Systems
Undefined references are particularly problematic in rag-systems due to:
- Complex inter-module dependencies
- Dynamic loading of retrieval components
- Type annotation requirements for document processing
- Integration with multiple AI/ML libraries
See also
- module-loading-failures
- python-errors
- production-failures
- assistant-rh
- code-quality