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

fix: Do not fail example data source job with invalid data #88

Merged
merged 2 commits into from
May 24, 2023

Conversation

snaselj
Copy link
Contributor

@snaselj snaselj commented Mar 3, 2023

About

I noticed example source job is failing now when I start with empty DB, providing PR that fixes that.

Done

  • Fixed to use "active" status as a fallback for missing status in example data source.

@@ -436,6 +436,10 @@ def load(self):
self.job.log_debug(message=f"Loaded {region} from remote Nautobot instance")

for site_entry in self._get_api_data("api/dcim/sites/"):
if not site_entry["status"]:
Copy link
Contributor

@chadell chadell Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions, but...

Why not apply the same logic as below:

region_name=site_entry["region"]["name"] if site_entry["region"] else None,
status_slug=site_entry["status"]["value"] if site_entry["status"] else None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because status field is required. I could assign some default value there, but seems to me better to ignore (and log) invalid objects, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, if it's not required any more in the Nautobot model, maybe we could update to make it optional?
https://github.com/nautobot/nautobot-plugin-ssot/blob/develop/nautobot_ssot/jobs/examples.py#L60

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status field is required:

>>> site = Site.objects.create()
>>> site.name = "My Site"
>>> site.validated_save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/nautobot/core/models/__init__.py", line 51, in validated_save
    self.full_clean()
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1251, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'status': ['This field cannot be blank.']}
>>> 

There seems to be some data inconsistency (missing status) in our demo data:
https://demo.nautobot.com/dcim/sites/hou/?tab=main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, if it's required we can't make it optional...
It's weird how data can be in this state if the DB schema is enforcing the status field...
How could we skip this validation and get into the DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chadell
Do you have some resolution pls?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this we should probably just be defaulting to Active Status. The problem is definitely in the demo data somehow allowing objects that require Status to be created without it blowing up the Job but we should have the Job handling it appropriately instead of just assuming the Status is set right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use "active" status as a fallback for missing status

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @snaselj! Does that make this ready for review?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdrew82
Not yet, dry run for the source job went smoothly, but without dry run, the job get's stuck. Will check it and let you know once everything works.

@snaselj snaselj force-pushed the u/snaselj-fix-example-source branch from 216b572 to 1fc7733 Compare March 3, 2023 15:15
@snaselj
Copy link
Contributor Author

snaselj commented Mar 3, 2023

Removed commit 216b572 as it was not working

@Kircheneer
Copy link
Contributor

@snaselj is this ready?

@snaselj snaselj force-pushed the u/snaselj-fix-example-source branch from 05d3293 to dc37b85 Compare May 24, 2023 09:50
@snaselj
Copy link
Contributor Author

snaselj commented May 24, 2023

Rebased to the latest develop

@snaselj snaselj marked this pull request as ready for review May 24, 2023 10:10
@snaselj snaselj requested a review from a team as a code owner May 24, 2023 10:10
@snaselj
Copy link
Contributor Author

snaselj commented May 24, 2023

This PR is ready for review now @Kircheneer

@Kircheneer Kircheneer merged commit 7fccdcb into develop May 24, 2023
16 checks passed
@jdrew82 jdrew82 deleted the u/snaselj-fix-example-source branch May 25, 2023 16:17
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.

None yet

4 participants