Kani999 / netbox-attachments

Plugin to manage attachments for any model
Apache License 2.0
55 stars 4 forks source link

Error on plugins page #23

Closed oasys closed 1 year ago

oasys commented 1 year ago

Clicking on "Plugins" and "Attachments" (to load the/plugins/netbox-attachments/netbox-attachments/ page) fails with an exception:

<class 'django.core.exceptions.FieldError'>

Cannot resolve keyword 'size' into field. Choices are: comments, content_type, content_type_id, created, custom_field_data, file, id, journal_entries, last_updated, name, object_id, parent, tagged_items, tags

Python version: 3.9.2
NetBox version: 3.3.9

Netbox-attachments version: 1.0.6

This is happening on our production instance (docker) as well as our dev server (VM installation). But, I cannot replicate the problem locally (docker). In all cases, I've restored the database from the production instance. I've changed the backend config (from S3 back to default/local) and it still fails. I've also upgraded Netbox 3.3.8 to 3.3.9.

Can you suggest where I might look to troubleshoot and isolate the cause?

Kani999 commented 1 year ago

@oasys I'll take a look at it. I'm using the same version at our production and this problem does not occur.

Does the error show some file location where the problem shows up?

Kani999 commented 1 year ago

The problem is when you try to order by file size. The size of the file is not stored in the database, so ordering will fail.

@oasys Should I add the file size to the database, or forbid the ordering and etc. on it?

When you go to NETBOX/user/preferences/ and clear out the table preferences, you should see the plugin page without a problem.

image

https://stackoverflow.com/questions/52953586/filter-by-file-size-in-django-filefield

Kani999 commented 1 year ago

Ok, I cannot find how to disable ordering. So I guess I will add file size to the database table.

oasys commented 1 year ago

Clearing the sort preference does work around the issue, thanks.

I saw that #24 attempts to fix this in a more general way, but that fails for me with:

ModuleNotFoundError: No module named 'utilities.json'

Kani999 commented 1 year ago

Clearing the sort preference does work around the issue, thanks.

I saw that #24 attempts to fix this in a more general way, but that fails for me with:

ModuleNotFoundError: No module named 'utilities.json'

Could you provide some more details? Traceback etc. I'm using this new version in production, and it work fine.

Kani999 commented 1 year ago

@oasys it seems utilities.json is a library created by NetBox. https://github.com/netbox-community/netbox/blob/develop/netbox/utilities/json.py So I don't know why your instance cannot be found it as a module.

Kani999 commented 1 year ago

Oh okay, i think I found the problem. You are using NetBox 3.3.9

but utilities.json was added at the latest version 3.4.3 I guess https://github.com/netbox-community/netbox/commit/af8bb0c4b9c0b8d6599f110f522bd1e598c40b88

And when I did a migration ( https://github.com/Kani999/netbox-attachments/pull/24/files#diff-a021e1288da10ed634e63b73cfae1a8b5b44908d8b74c404eca857982451326dR19 ) There was another line generated automatically by NetBox, which uses this.