question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[1.4] Job.run - self.request is None

See original GitHub issue

Environment

  • Python version: 3.9
  • Nautobot version: e02bb08e6c2a (v1.4.0rc1)

Steps to Reproduce

  1. Run a job
  2. Log self.request

Expected Behavior

self.request is not None

import pprint

class MyJob(Job):
    def run(self, data, commit=False):
        self.log_info(self.request, pprint.pformat(self.request, indent=4))
        ...

image

Observed Behavior

self.request is None

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jifoxcommented, Aug 12, 2022

What is the suggested way of logging the caller (username and ip) without accessing self.request?

This is the only reason why I am using it

0reactions
gsnider2195commented, Aug 15, 2022

@smk4664 I’m not able to replicate that problem on v1.4.0b1

Using your code above I’m able to get the repo to resync even when self.request = None as seen here:

class TestPullGitRepository(Job):
    class Meta:
        name = "Synchronize Repo"
        description = "Synchronize a repo."

    repository = ObjectVar(model=GitRepository, required=False)

    def run(self, data, commit):
        self.log_info(f"self.request is {self.request}")
        pull_git_repository_and_refresh_data(data["repository"].pk, self.request, self.job_result.pk)

image

If a request isn’t provided to pull_git_repository_and_refresh_data() I get this error message:

    def run(self, data, commit):
        self.log_info(f"self.request is {self.request}")
        pull_git_repository_and_refresh_data(data["repository"].pk, self.job_result.pk)

image

Were you able to verify that pull_git_repository_and_refresh_data was sending the job_result as the 3rd positional arg to refresh_datasource_content()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError when running database-changing Job from ` ...
In runjob , create a mock Request object via web_request_context and pass that instead of None; Enhance _handle_changed_object to gracefully ...
Read more >
Jobs - Nautobot Documentation - To the Core Docs!
Jobs are a way for users to execute custom logic on demand from within the ... to execute the job) are available as...
Read more >
Jobs - Nautobot Documentation
Jobs ¶. Jobs are a way for users to execute custom logic on demand from within the Nautobot UI. Jobs can interact directly...
Read more >
"dictionary update sequence element #0 has length 1; 2 is ...
I have an error message on Django 1.4:
Read more >
How to use sessions | Django documentation
Using sessions in views. When SessionMiddleware is activated, each HttpRequest object – the first argument to any Django view function – will have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found