Alef-Burzmali / netbox-data-flows

NetBox plugin to document data flows between systems and applications.
https://pypi.org/project/netbox-data-flows/
Apache License 2.0
37 stars 7 forks source link

Missing relations when migrating #1

Closed hst-tutorials closed 1 year ago

hst-tutorials commented 1 year ago

I found this plugin today and it is exactly what my company needs. Great idea!

I've installed the plugin on a fresh netbox instance and got the following error while running upgrade.sh

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv self.execute(*args, cmd_options) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute output = self.handle(*args, *options) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 98, in wrapped res = handle_func(args, kwargs) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 91, in handle self.check(databases=[database]) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 487, in check all_issues = checks.run_checks( File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 88, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 14, in check_url_config return check_resolver(resolver) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 24, in check_resolver return check_method() File "/opt/netbox/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 480, in check for pattern in self.url_patterns: File "/opt/netbox/venv/lib/python3.8/site-packages/django/utils/functional.py", line 49, in get res = instance.dict[self.name] = self.func(instance) File "/opt/netbox/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 696, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/opt/netbox/venv/lib/python3.8/site-packages/django/utils/functional.py", line 49, in get res = instance.dict[self.name] = self.func(instance) File "/opt/netbox/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 689, in urlconf_module return import_module(self.urlconf_name) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 848, in exec_module File "", line 219, in _call_with_frames_removed File "/opt/netbox/netbox/netbox/urls.py", line 9, in from extras.plugins.urls import plugin_admin_patterns, plugin_patterns, plugin_api_patterns File "/opt/netbox/netbox/extras/plugins/urls.py", line 28, in urlpatterns = import_object(f"{plugin_path}.urls.urlpatterns") File "/opt/netbox/netbox/extras/plugins/utils.py", line 31, in import_object spec.loader.exec_module(module) File "/opt/netbox/venv/lib/python3.8/site-packages/netbox_data_flows/urls.py", line 5, in from . import models, views File "/opt/netbox/venv/lib/python3.8/site-packages/netbox_data_flows/views/init.py", line 3, in from .dataflows import File "/opt/netbox/venv/lib/python3.8/site-packages/netbox_data_flows/views/dataflows.py", line 82, in class DataFlowRuleListView(generic.ObjectListView): File "/opt/netbox/venv/lib/python3.8/site-packages/netbox_data_flows/views/dataflows.py", line 84, in DataFlowRuleListView pk__in=models.DataFlow.get_disabled_queryset().only("pk") File "/opt/netbox/venv/lib/python3.8/site-packages/netbox_data_flows/models/dataflows.py", line 219, in get_disabled_queryset return cls.objects.filter( File "/opt/netbox/venv/lib/python3.8/site-packages/mptt/querysets.py", line 22, in get_descendants return self.model._tree_manager.get_queryset_descendants(self, args, **kwargs) File "/opt/netbox/venv/lib/python3.8/site-packages/mptt/managers.py", line 200, in get_queryset_descendants return self._get_queryset_relatives(queryset, "desc", include_self) File "/opt/netbox/venv/lib/python3.8/site-packages/mptt/managers.py", line 144, in _get_queryset_relatives if not q: File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 324, in bool self._fetch_all() File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1507, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 57, in iter results = compiler.execute_sql( File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1361, in execute_sql cursor.execute(sql, params) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "netbox_data_flows_dataflow" does not exist LINE 1: ...ght", "netbox_data_flows_dataflow"."tree_id" FROM `"netbox_da..

I think you forgot to create some relations in the database as they were given in your development environment.

Alef-Burzmali commented 1 year ago

Thanks for your interest :) For the moment, it is a work in progress and I plan to change most of the models to have something more practical now that I have a working poc, so I recommend you only play with this module in test.

The missing object is the table containing the dataflow, which should be creation in migration 0001, so that's strange. You can try this command to reapply the migrations of the module: python /opt/netbox/netbox/manage.py migrate netbox_data_flows I'll test more carefully on a clean install for next push, maybe I missed something.

hst-tutorials commented 1 year ago

Thank you for your response. I tried the command unfortunately it didn't resolve the issue. I looked at the first migration file but didnt find any traces of a table being created. But, please bear in mind that i'm not familiar with this kind of migrations

Alef-Burzmali commented 1 year ago

Can you please test again with the new release and let me know if you still have issues with the migrations?

You may have to drop the existing tables of the plugin if any were created.

hst-tutorials commented 1 year ago

I just tested out the v.0.2.0, works like a charm. Thank you!

Keep up the great work, I'm looking forward to how this project will develop, it has great potential in my opinion

Alef-Burzmali commented 1 year ago

Thank you!