inventree / InvenTree

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

Unable to create a new Build Order because of some error #4484

Closed LudeeD closed 1 year ago

LudeeD commented 1 year ago

Please verify that this bug has NOT been raised before.

Describe the bug*

When I go to create a new build order I get an error

InternalError

Error details can be found in the admin panel
URL: /api/build/?context=true

I see on the admin page the error: operator 2097673 is not a valid ordering operator, I've attached the traceback

Do you have any suggestions to where I might start looking for the issue ?

Thanks in advance for any feedback

Steps to Reproduce

  1. Create a new build order

Expected behaviour

The build order should be created

Deployment Method

Version Information

Version Information:

InvenTree-Version: 0.10.1 Django Version: 3.2.16 Commit Hash: c1f15ef Commit Date: 2023-02-25 Database: postgresql Debug-Mode: False Deployed using Docker: True Active plugins: False

Relevant log output

Traceback (most recent call last):

File "/root/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)

psycopg2.errors.InternalError_: operator 2097673 is not a valid ordering operator

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

Traceback (most recent call last):

File "/root/.local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)

File "/root/.local/lib/python3.9/site-packages/rest_framework/views.py", line 520, in options
data = self.metadata_class().determine_metadata(request, self)

File "/home/inventree/InvenTree/InvenTree/metadata.py", line 34, in determine_metadata
metadata = super().determine_metadata(request, view)

File "/root/.local/lib/python3.9/site-packages/rest_framework/metadata.py", line 67, in determine_metadata
actions = self.determine_actions(request, view)

File "/root/.local/lib/python3.9/site-packages/rest_framework/metadata.py", line 93, in determine_actions
actions[method] = self.get_serializer_info(serializer)

File "/home/inventree/InvenTree/InvenTree/metadata.py", line 133, in get_serializer_info
model_default_values = model_class.api_defaults(self.request)

File "/home/inventree/InvenTree/build/models.py", line 89, in api_defaults
'reference': generate_next_build_reference(),

File "/home/inventree/InvenTree/build/validators.py", line 9, in generate_next_build_reference
return Build.generate_reference()

File "/home/inventree/InvenTree/InvenTree/models.py", line 193, in generate_reference
ctx = cls.get_reference_context()

File "/home/inventree/InvenTree/InvenTree/models.py", line 141, in get_reference_context
'ref': cls.get_next_reference(),

File "/home/inventree/InvenTree/InvenTree/models.py", line 164, in get_next_reference
latest = cls.get_most_recent_item()

File "/home/inventree/InvenTree/InvenTree/models.py", line 155, in get_most_recent_item
return query.first()

File "/root/.local/lib/python3.9/site-packages/django/db/models/query.py", line 674, in first
for obj in (self if self.ordered else self.order_by('pk'))[:1]:

File "/root/.local/lib/python3.9/site-packages/django/db/models/query.py", line 280, in __iter__
self._fetch_all()

File "/root/.local/lib/python3.9/site-packages/django/db/models/query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))

File "/root/.local/lib/python3.9/site-packages/django/db/models/query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/root/.local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)

File "/root/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/root/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)

File "/root/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)

File "/root/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value

File "/root/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)

django.db.utils.InternalError: operator 2097673 is not a valid ordering operator
SchrodingersGat commented 1 year ago

@LudeeD this is a strange one indeed. Have you just performed an install or been running with the system for a while?

LudeeD commented 1 year ago

I've been running for a while. After a bit of investigation I am seeing some corruption on the database that might be triggering this issue. I intend to reinstall and recover from a previous backup and see. Its a strange thing to happen on a docker deployment. But I will see if can extract more info from it

SchrodingersGat commented 1 year ago

Please do let us know what you find, especially if you see that it points to an InvenTree bug!

LudeeD commented 1 year ago

I'll close the issue, I re-installed InvenTree and recover the data from a previous backup and everything is back to normal. I could not find the source of the problem and no indication that InvenTree might be the culprit so It doesn't make sense to leave this open

matmair commented 1 year ago

Please update us if this reappears; InvenTree should not corrupt the database after any time running.