ahawker / ulid

Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3
Apache License 2.0
705 stars 42 forks source link

deepcopy doesn't work on ULID object #452

Closed asgoel closed 4 years ago

asgoel commented 4 years ago

Running into a cryptic error when trying to deepcopy a ULID object:

>>> import ulid
>>> a = ulid.new()
>>> a
<ULID('01EAZF1038723PE2SS9BXRQC80')>
>>> import copy
>>> copy.deepcopy(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 173, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 147, in deepcopy
    y = copier(x, memo)
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 211, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 211, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 147, in deepcopy
    y = copier(x, memo)
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/ashu/.pyenv/versions/3.8.2/lib/python3.8/copy.py", line 162, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'memoryview' object

Any ideas?

ahawker commented 4 years ago

@asgoel Thanks for the report and apologies for the issue.

Deepcopy requires pickle support for the instance and we store a memoryview object that cannot be pickled. I'll work to add pickle support to get this addressed.

asgoel commented 4 years ago

@ahawker thank you for the super fast response! Confirmed that it works for me. I also use django-ulid, so was wondering if you could bump the version to force the ulid-py version to 0.1.0?

ahawker commented 4 years ago

@asgoel Yeah, I should have it out in a few hours.

ahawker commented 4 years ago

This should be available in django-ulid 0.0.4.