Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

"Device" can't be pickled #42

@samurang87

Description

@samurang87

Hello!

It looks like the "Device" class can't be pickled anymore with your latest major release. We'd like to upgrade to v.2+ but our tests that use multiprocessing fail because of this reason.

Environment details

  • OS type and version: local Mac OS 10.15.7, docker python-base:3.8.3-slim-buster
  • Python version: 3.8.3
  • pip version: 20.1.1
  • google-cloud-iot version: 2.0.1

Steps to reproduce

Try to pickle

Code example and resulting stack trace

import pickle
from google.cloud.iot_v1 import Device

device = Device(id="1")
pickled_device = pickle.dumps(device)
print(pickled_device)

Result:

Traceback (most recent call last):
  File "/Users/cmezzavilla/Code/aratrum/.vscode/scratch.py", line 7, in <module>
    pickled_device = pickle.dumps(device)
_pickle.PicklingError: Can't pickle <class 'Device'>: it's not the same object as __main__.Device

Stack trace from test

We have some tests running with multiprocessing, and when trying to upgrade python-iot from 1.0.0 to 2.0.1 they fail like so:

cls = <class 'multiprocessing.reduction.ForkingPickler'>
obj = ('108ed2f80', '__setitem__', ('europe-west1', {'pytest-of-cmezzavilla_aratrum_pytest-1': {'dev_26': id: "dev_26"
name:...pytest-of-cmezzavilla_aratrum_pytest-1/devices/dev_26"
config {
  version: 1
  binary_data: "invalid config"
}
}}), {})
protocol = None

    @classmethod
    def dumps(cls, obj, protocol=None):
        buf = io.BytesIO()
>       cls(buf, protocol).dump(obj)
E       _pickle.PicklingError: Can't pickle <class 'Device'>: attribute lookup Device on __main__ failed

Metadata

Metadata

Assignees

Labels

api: cloudiotIssues related to the googleapis/python-iot API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions