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

Using post_implementation alongside a !ref:create:<attr> runs at wrong time #153

Closed
jeffkala opened this issue May 15, 2024 · 1 comment · Fixed by #156
Closed

Using post_implementation alongside a !ref:create:<attr> runs at wrong time #153

jeffkala opened this issue May 15, 2024 · 1 comment · Fixed by #156

Comments

@jeffkala
Copy link

jeffkala commented May 15, 2024

Environment

  • Python version: 3.11
  • Nautobot version: 2.2.3
  • nautobot-design-builder version: 2.0.0

Expected Behavior

Having access to objects that you created during the run method in the post_implementation method.

Observed Behavior

When using !ref:create:name for example on a device, if you change it to !ref:create_or_update:name it works.

Steps to Reproduce

  1. Create a simple design to create a device.
---
devices:
  - "!create:name": "{{ device_hostname }}"
    "location__name": "{{ site_name }}"
    "status__name": "{{ device_status }}"
    "device_type__model": "{{ device_model }}"
    "role__name": "{{ device_role }}"
    "platform__name": "{{ device_platform }}"
  1. Add a simple post_implementation method and try to get the device object that was just created.
    def post_implementation(self, context, environment):
        """Generate bootstrap config."""
        current_device = Device.objects.get(name=context["device_hostname"])
  1. Run the design job.
    Results in a exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/extras/jobs.py", line 1136, in run_job
    result = job(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/extras/jobs.py", line 149, in __call__
    return self.run(*args, **deserialized_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot_design_builder/design_job.py", line 143, in run
    return self._run_in_transaction(dryrun, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot_design_builder/design_job.py", line 212, in _run_in_transaction
    raise ex
  File "/usr/local/lib/python3.11/site-packages/nautobot_design_builder/design_job.py", line 192, in _run_in_transaction
    self.post_implementation(context, self.environment)
  File "/opt/nautobot/git/nb2_jobs/designs/new_device_registration/jobs.py", line 64, in post_implementation
    current_device = Device.objects.get(name=context["device_hostname"])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
nautobot.dcim.models.devices.Device.DoesNotExist: Device matching query does not exist.
@abates
Copy link
Contributor

abates commented May 21, 2024

I believe this is fixed in pull #156. Any chance you can test?

abates added a commit that referenced this issue May 28, 2024
* fix: Corrects missing attributes with explicit `!create`

fixes #153

* style: Linting
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 a pull request may close this issue.

2 participants