Skip to content

label printing error: Can't pickle <class 'inventree_brother.brother_plugin.BrotherLabelPrinterDriver'> #9171

Closed

Description

@simonkuehling

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

  1. print a label via brother label printer (machine interface)
  2. 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

  1. added
    bug
    question
    triage:not-checked
    on Feb 24, 2025
  2. simonkuehling commented on Feb 24, 2025

    @simonkuehling
    ContributorAuthor

    Just found this discussion which matches the error as far as I can tell: #9020

  3. simonkuehling commented on Feb 25, 2025

    @simonkuehling
    ContributorAuthor

    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:

    offload_task(
    plugin_label.print_label,
    self.plugin_slug(),
    group='plugin',
    **print_args,
    )

    or probably more likely these - as we are using the machine interface:

    offload_task(
    driver.print_labels, machine, label, items, group='plugin', **print_kwargs
    )

    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...

  4. simonkuehling commented on Feb 25, 2025

    @simonkuehling
    ContributorAuthor

    Another data point: the devcontainer is running python 3.11.2 - but the docker image is running 3.11.11... which is unlikely to have an effect here, but nonetheless...

  5. wolflu05 commented on Feb 25, 2025

    @wolflu05
    Member

    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.)

  6. SchrodingersGat commented on Feb 26, 2025

    @SchrodingersGat
    Member

    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 PluginRegistry code we have a method call_plugin_function where 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?

  7. wolflu05 commented on Feb 26, 2025

    @wolflu05
    Member

    Sounds good 👍

  8. added this to the 1.0.0 milestone on Feb 26, 2025
  9. added
    plugin
    and removed
    question
    triage:not-checked
    on Feb 26, 2025
  10. SchrodingersGat commented on Feb 26, 2025

    @SchrodingersGat
    Member

    @simonkuehling please see proposed fix in #9191

    Are you able to pull that code and test? There are no changes required to the plugin.

  11. simonkuehling commented on Feb 27, 2025

    @simonkuehling
    ContributorAuthor

    @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!

  12. SchrodingersGat commented on Feb 27, 2025

    @SchrodingersGat
    Member

    you mentioned that you managed to replicate it earlier, can you share how you did that?

    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.

  13. simonkuehling commented on Feb 27, 2025

    @simonkuehling
    ContributorAuthor

    I tried the PR and got the following error in the Admin Center > Machines section:

    Image

    Configured are the two brother label printers like on my production server:

    Image

  14. SchrodingersGat commented on Feb 27, 2025

    @SchrodingersGat
    Member

    Strange, can't see that error here:

    Image

    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

  15. dieselburner commented on Feb 27, 2025

    @dieselburner

    I have reported this two weeks ago already, but maybe this was left unnoticed. Here.

  16. SchrodingersGat commented on Feb 27, 2025

    @SchrodingersGat
    Member

    @dieselburner sorry, missed that!

  17. simonkuehling commented on Feb 27, 2025

    @simonkuehling
    ContributorAuthor

    @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)

  18. simonkuehling commented on Feb 27, 2025

    @simonkuehling
    ContributorAuthor
  19. SchrodingersGat commented on Feb 27, 2025

    @SchrodingersGat
    Member

    The call_machine_function should 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?

  20. simonkuehling commented on Feb 28, 2025

    @simonkuehling
    ContributorAuthor

    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...

  21. SchrodingersGat commented on Feb 28, 2025

    @SchrodingersGat
    Member

    @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 worker

  22. simonkuehling commented on Feb 28, 2025

    @simonkuehling
    ContributorAuthor

    @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplugin

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions