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

Signal error to the GUI if a syntactically incorrect job is loaded from a git repository #138

Closed
Kircheneer opened this issue Mar 12, 2021 · 9 comments · Fixed by #2418
Closed
Assignees
Labels
good first issue Great issues for newcomers! type: feature Introduction of new or enhanced functionality to the application

Comments

@Kircheneer
Copy link
Contributor

Kircheneer commented Mar 12, 2021

Environment

Using nautobot-lab at 1.0.0b1

  • Python version: 3.8.5
  • Nautobot version: 1385ef2621ef (v1.0.0b2)

Proposed Functionality

If there is a syntactical error in a job file in a git repository there should be a warning or an error message in the sync job logs that indicates this.

Use Case

If someone was to write a job in a git repository and for example miss an import they wouldn't know if the error lies

  • in the communication between the repository and the Nautobot instance
  • in the job file itself
  • in the layout of the repository
  • some other place

Database Changes

None

External Dependencies

None

@jathanism
Copy link
Contributor

Hello @Kircheneer, thanks for the submission.

What is the current behavior you're experiencing? It sounds like if a job is attempting to be loaded, it is failing silently or in a non-obvious way? Can you please add some context on your experience? Thanks in advance!

@Kircheneer
Copy link
Contributor Author

I just did the following things:

  1. Reset the lab container
  2. Copy the example job (the new branch one) from the documentation in a git repository into a jobs folder under the repository root (that folder also contains an __init__.py file
  3. Run the job (working as expected)
  4. Change the description field in the Meta class to descriptio
  5. Refresh the data source in Nautobot
  6. Watch as the job silently disappears without an error message
  7. Change it back to description
  8. Refresh the data soruce in Nautobot
  9. The job is still not visible

Is there maybe some caching at play here which I am missing?

@jathanism
Copy link
Contributor

@glennmatthews Can you please help me confirm this one? :)

@jathanism
Copy link
Contributor

I am unable to reproduce this on Nautobot v1.0.0b2. The job appears to still load but the description field disappears.

Can you please build and install nautobot-lab from GitHub which will build b2 and see if this issue persists?

Thanks!

@jedelman8
Copy link
Contributor

Tagging @Kircheneer to see @jathanism's last comment!

@Kircheneer
Copy link
Contributor Author

Kircheneer commented Mar 24, 2021

That leads to a new error (when copying the default job from the docs again):

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/nautobot/extras/jobs.py", line 826, in _run_job
    output = job.run(data=data, commit=commit)
  File "/root/.nautobot/git/test/jobs/example.py", line 37, in run
    site = Site(
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 483, in __init__
    _setattr(self, field.name, rel_obj)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 215, in __set__
    raise ValueError(
ValueError: Cannot assign "'planned'": "Site.status" must be a "Status" instance.

Leaving that aside because it is not relevant to this issue (EDIT: #186), I have created this public repository. Try the "master" and the "test" branch in there. For me, the job from the "master" branch exhibits the behavior mentioned above, while the (faulty, runs with errors) script I copied from the docs in the "test" branch is recognized without issues. This is using nautobot-lab at the following commit:

commit 45a7bad52609263fca0c4c71e90a0ac0ea6986a3 (HEAD -> main, origin/main, origin/HEAD)
Merge: 0ed1147 978f9f9
Author: James Williams <amascuba@gmail.com>
Date:   Mon Mar 15 12:16:15 2021 -0500

    Merge pull request #19 from jtdub/superuser

    Populate Nautobot Lab with Sandbox Data

@jathanism
Copy link
Contributor

jathanism commented Mar 29, 2021

@Kircheneer That's progress! It does look like the NewBranch job you linked was based off the sample job of the same name.

In any case your issue is on line 41:

https://github.com/Kircheneer/nautobot_data/blob/master/jobs/example.py#L41

You want that to be an instance of a Status object now and not a choice enum. So you need these changes

# at the top
from nautobot.extras.models import Status

# one line 41
                status=Status.objects.get(slug="planned"),

Can you please see if updating your job fixes your issue?

@glennmatthews
Copy link
Contributor

I can verify the reported behavior using the "master" branch of the linked repo - the job fails (from the user's perspective) silently to load when accessing the Jobs UI, although the error is logged to the console at least:

21:00:27.643 ERROR   nautobot.jobs        jobs.py                               get_jobs() :
  Unable to load job example: f-string: expecting '}' (example.py, line 40)

It would be reasonable for us to add some handling logic to report errors as a banner on the Jobs page, along the lines of "The following job files could not be loaded...". Thanks for the report!

@glennmatthews glennmatthews added good first issue Great issues for newcomers! type: feature Introduction of new or enhanced functionality to the application and removed status: under review labels Mar 29, 2021
@jedelman8 jedelman8 added this to the v1.1.0 milestone Apr 7, 2021
@jedelman8 jedelman8 removed this from the v1.1.0 milestone Apr 29, 2021
@bryanculver
Copy link
Member

Needs to be retested for 1.3/1.4 as symptoms may have changed with concrete Job model.

@glennmatthews glennmatthews self-assigned this Sep 13, 2022
glennmatthews added a commit that referenced this issue Sep 13, 2022
glennmatthews added a commit that referenced this issue Sep 15, 2022
…ading fails (#2418)

* Fix #138: bubble up exceptions to the JobResult logs when Git repository job loading fails.

* Add unit test

* Adjust test for Python version differences
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Great issues for newcomers! type: feature Introduction of new or enhanced functionality to the application
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants