Skip to content

Fix module-level transformers import crashing manage.py test#11

Merged
andreisugu merged 3 commits intomainfrom
copilot/run-tests-and-fix-errors
Mar 11, 2026
Merged

Fix module-level transformers import crashing manage.py test#11
andreisugu merged 3 commits intomainfrom
copilot/run-tests-and-fix-errors

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 11, 2026

  • Identify root cause: from transformers import pipeline at module level in core/views.py causes import failure when transformers is not installed, crashing manage.py test
  • Fix: moved the transformers import inside the analyze_sentiment function where it's actually used (lazy import)
  • Identify CI failure: requests module was missing from requirements.txt, causing ModuleNotFoundError: No module named 'requests' in CI after the transformers fix
  • Fix: added requests to requirements.txt
  • Verified python manage.py test runs successfully (exits cleanly with "Found 0 test(s). Ran 0 tests in 0.000s")

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…e.py test to run

Co-authored-by: andreisugu <35407471+andreisugu@users.noreply.github.com>
Copilot AI changed the title [WIP] Run tests and handle reported errors Fix module-level transformers import crashing manage.py test Mar 11, 2026
@andreisugu
Copy link
Copy Markdown
Owner

@copilot
1m 43s
1s
Run python manage.py test
Traceback (most recent call last):
Found 0 test(s).
File "/home/runner/work/airsense/airsense/manage.py", line 22, in
main()
File "/home/runner/work/airsense/airsense/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/init.py", line 442, in execute_from_command_line
utility.execute()
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/init.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/commands/test.py", line 24, in run_from_argv
super().run_from_argv(argv)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/base.py", line 420, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/base.py", line 464, in execute
output = self.handle(*args, **options)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/commands/test.py", line 63, in handle
failures = test_runner.run_tests(test_labels)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/test/runner.py", line 1098, in run_tests
self.run_checks(databases)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/test/runner.py", line 1020, in run_checks
call_command("check", verbosity=self.verbosity, databases=databases)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/init.py", line 194, in call_command
return command.execute(*args, **defaults)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/base.py", line 464, in execute
output = self.handle(*args, **options)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/commands/check.py", line 81, in handle
self.check(
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/management/base.py", line 496, in check
all_issues = checks.run_checks(
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/checks/registry.py", line 89, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/urls/resolvers.py", line 531, in check
for pattern in self.url_patterns:
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/utils/functional.py", line 47, in get
res = instance.dict[self.name] = self.func(instance)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/urls/resolvers.py", line 718, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/utils/functional.py", line 47, in get
res = instance.dict[self.name] = self.func(instance)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/urls/resolvers.py", line 711, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/home/runner/work/airsense/airsense/airsense/urls.py", line 26, in
path('', include('core.urls')),
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/django/urls/conf.py", line 39, in include
urlconf_module = import_module(urlconf_module)
File "/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/home/runner/work/airsense/airsense/core/urls.py", line 3, in
from . import views
File "/home/runner/work/airsense/airsense/core/views.py", line 6, in
import requests
ModuleNotFoundError: No module named 'requests'
Error: Process completed with exit code 1.

Co-authored-by: andreisugu <35407471+andreisugu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 11, 2026

@copilot
1m 43s
1s
...

The CI was still failing because requests was missing from requirements.txt. After the transformers fix, Django could load URL configs but then crashed on import requests (used throughout views.py for weather/pollen/IP APIs). Fixed in d11f85f by adding requests to requirements.txt.

@andreisugu andreisugu marked this pull request as ready for review March 11, 2026 12:54
@andreisugu andreisugu merged commit 0cea17d into main Mar 11, 2026
3 checks passed
@andreisugu andreisugu deleted the copilot/run-tests-and-fix-errors branch March 11, 2026 12:55
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

Successfully merging this pull request may close these issues.

2 participants