1.7 KiB
1.7 KiB
ImportError Fix Summary
Issue
Error: ImportError: cannot import name 'create_action_from_negative_survey' from 'apps.surveys.tasks'
Location: apps/surveys/public_views.py, line 240
Root Cause
The function create_action_from_negative_survey did exist in apps/surveys/tasks.py, but Python was unable to import it due to stale bytecode cache. This commonly occurs when:
- The Python source file is modified
- The
.pyc(compiled Python) files in__pycache__directories become outdated - Python imports the old cached bytecode instead of the updated source
Solution
Cleared all Python bytecode cache files and directories:
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
find . -name "*.pyc" -delete 2>/dev/null
Verification
Created and ran test script (test_import_fix.py) to verify the fix:
from apps.surveys.tasks import create_action_from_negative_survey
Result: ✅ Import successful
Function Details
- Function Name:
create_action_from_negative_survey - Location:
apps/surveys/tasks.py - Purpose: Celery task to create PX Actions from negative survey responses
- Decorators:
@shared_task
Next Steps
- Restart the Django development server to ensure fresh imports
- Test survey submission at
/surveys/s/{token}/endpoint - Verify that negative surveys properly trigger PX Action creation
Prevention
To prevent similar issues in the future:
- Always clear cache after major code changes
- Consider adding a management command to clear cache:
python manage.py clear_cache - Use
python manage.py runserver --noreloadduring development to reduce cache issues