Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_job_for_testing fails if no request is provided #2733

Closed
gsnider2195 opened this issue Nov 3, 2022 · 0 comments · Fixed by #2734
Closed

run_job_for_testing fails if no request is provided #2733

gsnider2195 opened this issue Nov 3, 2022 · 0 comments · Fixed by #2734
Assignees
Labels
type: bug Something isn't working as expected

Comments

@gsnider2195
Copy link
Contributor

Environment

  • Nautobot version (Docker tag too if applicable): v1.5.0a1
  • Python version: v3.10.7
  • Database platform, version: postgres 13
  • Middleware(s):

Steps to Reproduce

from nautobot.utilities.testing import run_job_for_testing
j=Job.objects.get(job_class_name="ExampleJob")
run_job_for_testing(j, data={}, commit=True)

Expected Behavior

Method runs the job in web_request_context which dynamically generates a request

Observed Behavior

Exception:

18:29:52.547 INFO    nautobot.jobs.ExampleJob jobs.py                                run_job() :
  Running job (commit=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/source/nautobot/utilities/testing/__init__.py", line 102, in run_job_for_testing
    run_job(data=data, request=wrapped_request, commit=commit, job_result_pk=job_result.pk)
  File "/usr/local/lib/python3.10/site-packages/celery/local.py", line 188, in __call__
    return self._get_current_object()(*a, **kw)
  File "/usr/local/lib/python3.10/site-packages/celery/app/task.py", line 392, in __call__
    return self.run(*args, **kwargs)
  File "/source/nautobot/extras/jobs.py", line 1251, in run_job
    change_context = context_class(user=request.user, context_detail=job_model.slug)
AttributeError: '_GeneratorContextManager' object has no attribute 'user'
@gsnider2195 gsnider2195 self-assigned this Nov 3, 2022
@gsnider2195 gsnider2195 added the type: bug Something isn't working as expected label Nov 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant