inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 781 forks source link

Adding report template #8238

Closed hagai-biton closed 1 month ago

hagai-biton commented 1 month ago

Please verify that this bug has NOT been raised before.

Describe the bug*

when trying to add a new stock location template I get server error 500 attached is the error report.

Steps to Reproduce

  1. go to "/platform/settings/admin/reports"
  2. click the + sign and fill the form
  3. link to the html template you created
  4. try to save

Expected behaviour

I want to add a new html with added features to the report options

Deployment Method

Version Information

Version Information:

InvenTree-Version: 0.16.4 Django Version: 4.2.15 Commit Hash: 83be1b8 Commit Date: 2024-09-30

Database: postgresql Debug-Mode: False Deployed using Docker: True Platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with Installer: DOC

Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.1.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.1.0'}, {'name': 'InvenTreeLabelMachine', 'slug': 'inventreelabelmachine', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}]

Please verify if you can reproduce this bug on the demo site.

Relevant log output

Traceback (most recent call last):

File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute

return self.cursor.execute(sql, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 732, in execute

raise ex.with_traceback(None)

psycopg.errors.NotNullViolation: null value in column "attach_to_model" of relation "report_reporttemplate" violates not-null constraint

DETAIL: Failing row contains (11, {}, location report with name, report/report/inventree_report_location_names.html, location report with name, 2, A4, f, output.pdf, t, stocklocation, , null).

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

Traceback (most recent call last):

File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch

response = handler(request, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 242, in post

return self.create(request, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/inventree/src/backend/InvenTree/InvenTree/mixins.py", line 22, in create

self.perform_create(serializer)

File "/root/.local/lib/python3.11/site-packages/rest_framework/mixins.py", line 24, in perform_create

serializer.save()

File "/home/inventree/src/backend/InvenTree/InvenTree/serializers.py", line 295, in save

super().save(**kwargs)

File "/root/.local/lib/python3.11/site-packages/rest_framework/serializers.py", line 212, in save

self.instance = self.create(validated_data)

^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/inventree/src/backend/InvenTree/InvenTree/serializers.py", line 309, in create

return super().create(initial_data)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/serializers.py", line 962, in create

instance = ModelClass._default_manager.create(**validated_data)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 658, in create

obj.save(force_insert=True, using=self.db)

File "/home/inventree/src/backend/InvenTree/report/models.py", line 145, in save

super().save()

File "/home/inventree/src/backend/InvenTree/InvenTree/models.py", line 156, in save

super().save(*args, **kwargs)

File "/home/inventree/src/backend/InvenTree/InvenTree/models.py", line 119, in save

super().save(*args, **kwargs)

File "/root/.local/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save

self.save_base(

File "/root/.local/lib/python3.11/site-packages/django/db/models/base.py", line 877, in save_base

updated = self._save_table(

^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/base.py", line 1020, in _save_table

results = self._do_insert(

^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/base.py", line 1061, in _do_insert

return manager._insert(

^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 1805, in _insert

return query.get_compiler(using=using).execute_sql(returning_fields)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql

cursor.execute(sql, params)

File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute

return self._execute_with_wrappers(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers

return executor(sql, params, many, context)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute

with self.db.wrap_database_errors:

File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__

raise dj_exc_value.with_traceback(traceback) from exc_value

File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute

return self.cursor.execute(sql, params)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 732, in execute

raise ex.with_traceback(None)

django.db.utils.IntegrityError: null value in column "attach_to_model" of relation "report_reporttemplate" violates not-null constraint

DETAIL: Failing row contains (11, {}, location report with name, report/report/inventree_report_location_names.html, location report with name, 2, A4, f, output.pdf, t, stocklocation, , null). 
SchrodingersGat commented 1 month ago

@hagai-biton thanks for the report. I am not able to reproduce this, but the error message seems to indicate that the database has not been correctly migrated after an update to InvenTree.

Can you please run the following command, and then test again:

docker compose run --rm inventree-server invoke update

(as per the documentation )

hagai-biton commented 1 month ago

Hi Oliver. This solved my problem. Thank you for the input.

On Sun, 6 Oct 2024 at 13:30, Oliver @.***> wrote:

@hagai-biton https://github.com/hagai-biton thanks for the report. I am not able to reproduce this, but the error message seems to indicate that the database has not been correctly migrated after an update to InvenTree.

Can you please run the following command, and then test again:

docker compose run --rm inventree-server invoke update

(as per the documentation https://docs.inventree.org/en/stable/start/docker_install/#updating-inventree )

— Reply to this email directly, view it on GitHub https://github.com/inventree/InvenTree/issues/8238#issuecomment-2395384513, or unsubscribe https://github.com/notifications/unsubscribe-auth/A47DWBZOPWRKUHWPUZOMJU3Z2EGLLAVCNFSM6AAAAABPLZ27PCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJVGM4DINJRGM . You are receiving this because you were mentioned.Message ID: @.***>

-- תודה חגי ביטון