Repository navigation
Closed
Description
Please verify that this bug has NOT been raised before.
- I checked and didn't find a similar issue
Describe the bug*
I just updated my docker install to the latest image today and am running into issues with label printing via the inventree-brother-plugin that I cannot make sense of right now.
The error message is (full traceback below)
Can't pickle <class 'inventree_brother.brother_plugin.BrotherLabelPrinterDriver'>: it's not the same object as inventree_brother.brother_plugin.BrotherLabelPrinterDriver
Steps to Reproduce
- print a label via brother label printer (machine interface)
- no label is printed, error message instead
Expected behaviour
(label printed)
Deployment Method
- Docker
- Package
- Bare metal
- Other - added info in Steps to Reproduce
Version Information
| InvenTree Version | 0.18.0 dev |
|---|
Version Information
Development Version
InvenTree Version
0.18.0 dev
API Version
315
Python Version
3.11.11
Django Version
4.2.19
Commit Hash
49eaeda
Commit Date
2025-02-24
Commit Branch
Please verify if you can reproduce this bug on the demo site.
- I can reproduce this bug on the demo site.
Relevant log output
Message: Can't pickle <class 'inventree_brother.brother_plugin.BrotherLabelPrinterDriver'>: it's not the same object as inventree_brother.brother_plugin.BrotherLabelPrinterDriver
Timestamp: 2025-02-24 15:26
Path: InvenTree.offload_task
Traceback
Traceback (most recent call last):
File "/home/inventree/src/backend/InvenTree/InvenTree/tasks.py", line 208, in offload_task
task.run()
File "/root/.local/lib/python3.11/site-packages/django_q/tasks.py", line 730, in run
self.id = async_task(self.func, *self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django_q/tasks.py", line 71, in async_task
pack = SignedPackage.dumps(task)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django_q/signing.py", line 16, in dumps
return signing.dumps(
^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/core/signing.py", line 152, in dumps
return TimestampSigner(key=key, salt=salt).sign_object(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/core/signing.py", line 250, in sign_object
data = serializer().dumps(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django_q/signing.py", line 36, in dumps
return pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_pickle.PicklingError: Can't pickle <class 'inventree_brother.brother_plugin.BrotherLabelPrinterDriver'>: it's not the same object as inventree_brother.brother_plugin.BrotherLabelPrinterDriver
Activity
simonkuehling commentedon Feb 24, 2025
Just found this discussion which matches the error as far as I can tell: #9020
simonkuehling commentedon Feb 25, 2025
Digging into this I found references that it could be a serialization issue when passing an object instance to
async_task()instead of a plain method - which would be the case in these lines:InvenTree/src/backend/InvenTree/plugin/base/label/mixins.py
Lines 188 to 193 in df60b1b
or probably more likely these - as we are using the machine interface:
InvenTree/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
Lines 98 to 100 in df60b1b
Could this be an issue here?
On the other hand it is working flawlessly in my devcontainer - replicating the full machines setting with two brother label printers as on my production server...
simonkuehling commentedon Feb 25, 2025
Another data point: the devcontainer is running python
3.11.2- but the docker image is running3.11.11... which is unlikely to have an effect here, but nonetheless...wolflu05 commentedon Feb 25, 2025
Hi, this seems to be some kind of similar error we had before, and I thought it was fixed, it must be a change on inventree or its dependencies. I have very limited time currently. I would really appreciate if somebody would come up with a solution. Some ideas would be to try which arguments of this offload task function create this error. Then try to identify why this happens.
(Just FYI, A cache is always needed for the machine printing feature, otherwise it won't work.)
SchrodingersGat commentedon Feb 26, 2025
I can reproduce this issue quite trivially. Digging down into it a little bit, I think that passing class objects around to offload to the background worker is going to inevitably cause these sorts of problems.
In the
PluginRegistrycode we have a methodcall_plugin_functionwhere you offload the unique slug of the plugin (string) and the name of the method (string). The background worker can then easily store these objects and find the right plugin and method.I think we need to consider a similar approach for the "machines" registry. We have a "call machine function" command where we pass the unique identifier for the machine, as well as the function to run. This way, we do not have to worry about incompatible module identifiers between the front-end and back-end code.
This would also robustify the "machines" interface against other associated caching issues
@wolflu05 thoughts here in general?
wolflu05 commentedon Feb 26, 2025
Sounds good 👍
SchrodingersGat commentedon Feb 26, 2025
@simonkuehling please see proposed fix in #9191
Are you able to pull that code and test? There are no changes required to the plugin.
simonkuehling commentedon Feb 27, 2025
@SchrodingersGat for some reason I wasn‘t able to replicate the error in the devcontainer setup yet, only on the production server (standard docker setup) - you mentioned that you managed to replicate it earlier, can you share how you did that?
I‘m happy to test the PR, sure!
SchrodingersGat commentedon Feb 27, 2025
In one devcontainer setup, I was able to reproduce. In another (different computer) I was not able to, so not sure what is going on there.
simonkuehling commentedon Feb 27, 2025
I tried the PR and got the following error in the
Admin Center > Machinessection:Configured are the two brother label printers like on my production server:
SchrodingersGat commentedon Feb 27, 2025
Strange, can't see that error here:
Can you try with a single machine instance, and see if you can print (and avoid the pickling error)?
This new error may be separate and unrelated
dieselburner commentedon Feb 27, 2025
I have reported this two weeks ago already, but maybe this was left unnoticed. Here.
SchrodingersGat commentedon Feb 27, 2025
@dieselburner sorry, missed that!
simonkuehling commentedon Feb 27, 2025
@SchrodingersGat with only one machine configured I get just one of these registry error lines.
Along with these errors I cannot get the setup printing - printing is confirmed as successful in the UI, but no label is printed and besides the registry error I cannot find any other error message around that...
EDIT: after a few inventree-server restarts I now have two lines again (with only one machine configured)
simonkuehling commentedon Feb 27, 2025
Digging further, I agree that the registry errors are likely unrelated here.
But, on topic: I added a breakpoint at
https://github.com/schrodingersgat/inventree/blob/1b1714458bc0a9751c46a8ee8c0c71420c2e0a48/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py#L100
and
https://github.com/schrodingersgat/inventree/blob/1b1714458bc0a9751c46a8ee8c0c71420c2e0a48/src/backend/InvenTree/machine/registry.py#L336
and found that
offload_taskgets called correctly, butcall_machine_function()never gets called for some reason... does this help?SchrodingersGat commentedon Feb 27, 2025
The
call_machine_functionshould be offloaded to the background worker process - so a breakpoint on the frontend code would not work.Can you please check if the worker task is showing any errors?
simonkuehling commentedon Feb 28, 2025
oh, I see - can you give me a tip on how to get to the worker task outputs during a vscode debug run? haven't had much experience with debugging complex projects like this in vscode yet...
SchrodingersGat commentedon Feb 28, 2025
@simonkuehling ok well firstly I have updated the code so that now it will run in the foreground if the worker is not running.
However that does not test the bug at play here to do with "pickle" errors.
So, in vscode open a new terminal and simply run
invoke workersimonkuehling commentedon Feb 28, 2025
@SchrodingersGat ok... thanks for the tip - appreciate your patience a lot. I did not realize that I had to start the worker manually...
Running the most recent state of the PR now - and with a background worker running - label printing works flawlessly with two networked brother label printers from within my devcontainer!