Onemind-Services-LLC / netbox-secrets

Enhance your secret management with encrypted storage and flexible, user-friendly features.
Apache License 2.0
96 stars 8 forks source link

[Bug]: User Key Add Error: `'str' object has no attribute '_meta'` #116

Closed gpmidi closed 8 months ago

gpmidi commented 9 months ago

NetBox Secrets plugin version

v1.9.0

NetBox version

v3.6.7

Steps to Reproduce

  1. Go to User Key | Add New Key
  2. Enter a RSA key - I had the problem with both 4k and 8k keys. Didn't test others.
  3. Click "Create"
  4. Get error page with 'str' object has no attribute '_meta'

Might be related to Netbox issue 7474

Expected Behavior

A new public key should be added for my user

Observed Behavior

<class 'AttributeError'>

'str' object has no attribute '_meta'

Python version: 3.11.6
NetBox version: 3.6.7
Plugins: 
  netbox_cable_labels: 0.0.3
  netbox_dns: 0.21.8
  netbox_inventory: 1.5.2
  netbox_secrets: 1.9.0
abhi1693 commented 9 months ago

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v3.6.7. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

moistpope commented 7 months ago

I'm seeing the same issue on the newest versions of netbox-docker and netbox-secrets.

Just created a completely bare, fresh install with no objects other than my user. Tried with 2048 and 4096-bit keys and got the same message as OP.

AttributeError at /plugins/secrets/user-key/edit/
'str' object has no attribute '_meta'
Request Method: POST
Request URL:    http://localhost:8050/plugins/secrets/user-key/edit/
Django Version: 4.2.9
Exception Type: AttributeError
Exception Value:    
'str' object has no attribute '_meta'
Exception Location: /opt/netbox/netbox/utilities/templatetags/builtins/filters.py, line 95, in meta
Raised during:  netbox_secrets.views.UserKeyEditView
Python Executable:  /opt/netbox/venv/bin/python
Python Version: 3.11.4
Python Path:    
['/opt/netbox/netbox/',
 '/usr/lib/python311.zip',
 '/usr/lib/python3.11',
 '/usr/lib/python3.11/lib-dynload',
 '/opt/netbox/venv/lib/python3.11/site-packages']
Server time:    Tue, 13 Feb 2024 02:16:50 +0000
Tail end of the trace ``` /opt/netbox/venv/lib/python3.11/site-packages/django/template/base.py, line 966, in render_annotated """ Render the node. If debug is True and an exception occurs during rendering, the exception is annotated with contextual line information where it occurred in the template. For internal usage this method is preferred over using the render method directly. """ try: return self.render(context) ^^^^^^^^^^^^^^^^^^^^ … except Exception as e: if context.template.engine.debug: # Store the actual node that caused the exception. if not hasattr(e, "_culprit_node"): e._culprit_node = self if ( Local vars Variable Value context [{'True': True, 'False': False, 'None': None}, {}, {}, {'userkey': , 'form': }] self } singular=[, , ] plural=[]> /opt/netbox/venv/lib/python3.11/site-packages/django/templatetags/i18n.py, line 156, in render if self.message_context: message_context = self.message_context.resolve(context) else: message_context = None # Update() works like a push(), so corresponding context.pop() is at # the end of function context.update( {var: val.resolve(context) for var, val in self.extra_context.items()} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ … ) singular, vars = self.render_token_list(self.singular) if self.plural and self.countervar and self.counter: count = self.counter.resolve(context) if not isinstance(count, (Decimal, float, int)): raise TemplateSyntaxError( Local vars Variable Value context [{'True': True, 'False': False, 'None': None}, {}, {}, {'userkey': , 'form': }] message_context None nested False self } singular=[, , ] plural=[]> /opt/netbox/venv/lib/python3.11/site-packages/django/templatetags/i18n.py, line 156, in if self.message_context: message_context = self.message_context.resolve(context) else: message_context = None # Update() works like a push(), so corresponding context.pop() is at # the end of function context.update( {var: val.resolve(context) for var, val in self.extra_context.items()} ^^^^^^^^^^^^^^^^^^^^ … ) singular, vars = self.render_token_list(self.singular) if self.plural and self.countervar and self.counter: count = self.counter.resolve(context) if not isinstance(count, (Decimal, float, int)): raise TemplateSyntaxError( Local vars Variable Value .0 context [{'True': True, 'False': False, 'None': None}, {}, {}, {'userkey': , 'form': }] val var 'object_type' /opt/netbox/venv/lib/python3.11/site-packages/django/template/base.py, line 742, in resolve else: arg_vals.append(arg.resolve(context)) if getattr(func, "expects_localtime", False): obj = template_localtime(obj, context.use_tz) if getattr(func, "needs_autoescape", False): new_obj = func(obj, autoescape=context.autoescape, *arg_vals) else: new_obj = func(obj, *arg_vals) ^^^^^^^^^^^^^^^^^^^^ … if getattr(func, "is_safe", False) and isinstance(obj, SafeData): obj = mark_safe(new_obj) else: obj = new_obj return obj Local vars Variable Value arg 'verbose_name' arg_vals ['verbose_name'] args [(False, 'verbose_name')] context [{'True': True, 'False': False, 'None': None}, {}, {}, {'userkey': , 'form': }] func ignore_failures False lookup False obj '' self string_if_invalid '' /opt/netbox/netbox/utilities/templatetags/builtins/filters.py, line 95, in meta Return the specified Meta attribute of a model. This is needed because Django does not permit templates to access attributes which begin with an underscore (e.g. _meta). Args: model: A Django model class or instance attr: The attribute name """ return getattr(model._meta, attr, '') ^^^^^^^^^^^ … @register.filter() def placeholder(value): """ Render a muted placeholder if the value equates to False. Local vars Variable Value attr 'verbose_name' model '' ```
abhi1693 commented 7 months ago

Unless someone provides us the steps to reproduce this bug, it's not possible for us to find which condition might have caused this. We too use our plugin and have not yet encountered it anywhere.

moistpope commented 7 months ago

As provided in the setup instructions:

git clone -b release https://github.com/netbox-community/netbox-docker.git
cd netbox-docker

plugin_requirements.txt

netbox-secrets

Dockerfile-Plugins

FROM netboxcommunity/netbox:latest

COPY ./plugin_requirements.txt /opt/netbox/
RUN /opt/netbox/venv/bin/pip install  --no-warn-script-location -r /opt/netbox/plugin_requirements.txt

# These lines are only required if your plugin has its own static files.
COPY configuration/configuration.py /etc/netbox/config/configuration.py
COPY configuration/plugins.py /etc/netbox/config/plugins.py
RUN SECRET_KEY="dummydummydummydummydummydummydummydummydummydummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input

docker-compose.override.yml

version: '3.4'
services:
  netbox:
    image: netbox:latest-plugins
    ports:
      - "8050:8080"
    build:
      context: .
      dockerfile: Dockerfile-Plugins
  netbox-worker:
    image: netbox:latest-plugins
    build:
      context: .
      dockerfile: Dockerfile-Plugins
  netbox-housekeeping:
    image: netbox:latest-plugins
    build:
      context: .
      dockerfile: Dockerfile-Plugins

plugins.py

PLUGINS = ["netbox_secrets"]

PLUGINS_CONFIG = {
    "netbox_secrets": {},
}
docker compose build --no-cache
docker-compose up -d
docker compose exec netbox /opt/netbox/netbox/manage.py createsuperuser

log into web interface Click on 'Plugins' in the navigation bar Click on 'User key' under 'NETBOX-SECRETS'

Add User Key Enter any 1024, 2048, or 4096-bit RSA public key

See error from previous message

abhi1693 commented 7 months ago

Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

Rather than setup instructions, please provide the steps that caused the issue in the first place. I did exactly as you outlined in your setup instructions and I cannot reproduce the issue. So, I'm left to believe that this is a user error for now as you are failing to provide the steps.