nautobot-app-golden-config icon indicating copy to clipboard operation
nautobot-app-golden-config copied to clipboard

KeyError when trying to configure columns for Config Compliance table view

Open joewesch opened this issue 1 year ago • 2 comments

Environment

  • Python version: 3.11.10
  • Nautobot version: 2.3.6
  • nautobot-golden-config version: 2.1.2

Expected Behavior

I expected to be able to set the columns in the table view on the Config Compliance page

Observed Behavior

<class 'KeyError'>

'dynamic_group_count'

Steps to Reproduce

  1. Go to Config Compliance table view
  2. Click the Configure button to edit the columns
  3. Make any (or no changes) and hit Save

Issue originally reported via slack: https://networktocode.slack.com/archives/C01NWPK6WHL/p1727879954240279

Workaround

Since this issue can cause the Config Compliance view to be rendered inoperable, you can use the following steps to remediate the issue temporarily:

  1. Click on your username in the side navigation bar and go to Profile
  2. Go to Preferences
  3. Select tables.ConfigComplianceTable.columns and click Clear Selected

joewesch avatar Oct 03 '24 13:10 joewesch

@glennmatthews Does it seem reasonable to just turn dynamic groups off this model for now? e.g. is_dynamic_group_associable_model = False on the model.

itdependsnetworks avatar Oct 03 '24 14:10 itdependsnetworks

If you don't see a use case for dynamic groups of ConfigCompliance, absolutely that would be the appropriate fix. See also the note added in v2.3.6 release notes (we missed it in v2.3.0, sorry!):

App Developers should review the feature set of their data models and consider whether their models should opt into or out of inclusion in Dynamic Groups, Contacts/Teams, Object Metadata, and Saved Views via the inclusion or omission of appropriate model mixins and flag variables. Refer to the developer documentation for details.

glennmatthews avatar Oct 03 '24 15:10 glennmatthews

~I think the fix here is just changing the order of operations in tables.py here~

Don't do the above. We shouldn't be touching Table.base_columns after calling BaseTable.__init__. See the below traceback from recreating the bug:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/response.py", line 74, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/core/views/renderers.py", line 370, in render
    return super().render(data, accepted_media_type=accepted_media_type, renderer_context=renderer_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/renderers.py", line 727, in render
    context = self.get_context(data, accepted_media_type, renderer_context)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/core/views/renderers.py", line 236, in get_context
    table = self.construct_table(view, request=request, permissions=permissions)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/core/views/renderers.py", line 97, in construct_table
    table = table_class(
            
  File "/source/nautobot_golden_config/tables.py", line 180, in __init__
    super().__init__(*args, **kwargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/core/tables.py", line 153, in __init__
    self.columns.hide(name)
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django_tables2/columns/base.py", line 797, in hide
    self.columns[name].column.visible = False
    ^^^^^^^^^^^^^^^^^^

Exception Type: KeyError at /plugins/golden-config/config-compliance/
Exception Value: 'dynamic_group_count'

gsnider2195 avatar Nov 08 '24 19:11 gsnider2195