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 CustomFieldChoices Import #131

Merged
merged 5 commits into from
Feb 15, 2024
Merged

Conversation

snaselj
Copy link
Contributor

@snaselj snaselj commented Feb 14, 2024

Closes: NaN

What's Changed

  • Fixed importing CustomFieldChoices.
  • Updated test summaries.
  • Added pre_import feature to skip records.
  • Fixed fail, when importing non-existent content types for ObjectChange model.
  • Added more test data.
  • Separated custom fields and object change customization to distinct module.
  • Avoided double log for save errors.

- Added `pre_import` feature to skip records.
- Added more test data.
- Skipped importing non-existent content types for `ObjectChange` model.
- Separated custom fields and object change customization to distinct
  module.
@snaselj snaselj marked this pull request as ready for review February 14, 2024 14:42
@@ -254,11 +256,13 @@ def import_data(self) -> None:
else:
wrapper = self.configure_model(content_type)

if wrapper.pre_import:
if not wrapper.pre_import(data, 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the significance of 1 here and 2 below? Looks like you're using it in create_choice_set() to skip some work if it's 1 - can we use constants or something to make this more obvious? Can you document it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the first pass, described in the documentation and mentioned in the comment few lines above (252)

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling pre_import twice with a different number, should we have two separate wrapper functions that get called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using single function here means less code to be used. Most pre_import implementations has common code for both passes.

@@ -254,11 +256,13 @@ def import_data(self) -> None:
else:
wrapper = self.configure_model(content_type)

if wrapper.pre_import:
if not wrapper.pre_import(data, 1):
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't this skip increment wrapper.skipped_count?

Copy link
Contributor Author

@snaselj snaselj Feb 14, 2024

Choose a reason for hiding this comment

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

As it is the first pass, this doesn't import data, but enhance the importer structure. Actual skipping is done in the second pass.

nautobot_netbox_importer/diffsync/models/custom_fields.py Outdated Show resolved Hide resolved
Comment on lines +17 to +29
contenttypes.ContentType \
dcim.Device \
dcim.DeviceRole \
dcim.DeviceType \
dcim.Manufacturer \
dcim.Site \
extras.CustomField \
extras.CustomFieldChoiceSet \
extras.JournalEntry \
extras.ObjectChange \
ipam.FHRPGroup \
tenancy.Tenant \
tenancy.TenantGroup \
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a weirdly specific subset of models - can we document why this specific list was chosen, and why other models were omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will improve the documentation in the other PR.

This custom set is a minimal import with things that needs to be tested. Models are going to be added here.

@@ -62,6 +62,7 @@ class ModelSummary(NamedTuple):
nautobot_flags: str
default_reference_uid: Union[str, bool, int, float, None]
imported_count: int
skipped_count: int
Copy link
Contributor

Choose a reason for hiding this comment

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

Where's the documentation of what these fields mean? skipped_count means number of models skipped? number of instances skipped? or what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this is in related to single model, it means number of models instances, that has been skipped. Will improve the documentation in a separate PR.

nautobot_netbox_importer/diffsync/models/custom_fields.py Outdated Show resolved Hide resolved
This was referenced Feb 15, 2024
@snaselj snaselj merged commit d6787b9 into develop Feb 15, 2024
14 checks passed
@snaselj snaselj deleted the u/snaselj-napps-239-custom-fields branch February 15, 2024 15:17
@snaselj snaselj mentioned this pull request Feb 19, 2024
2 tasks
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.

2 participants