Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't deepcopy JsonDicts (and other containers) #115

Open
czue opened this issue Oct 29, 2014 · 5 comments
Open

can't deepcopy JsonDicts (and other containers) #115

czue opened this issue Oct 29, 2014 · 5 comments

Comments

@czue
Copy link
Member

czue commented Oct 29, 2014

not sure if this is an issue or expected behavior

>>> from jsonobject import *
>>> import copy
>>> class Obj(JsonObject):
...   foo = DictProperty()
... 
>>> obj = Obj(foo={"some": "value"})
>>> copy.deepcopy(obj.foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.7/copy.py", line 174, in deepcopy
    y = copier(memo)
TypeError: cannot deepcopy this pattern object
dannyroberts referenced this issue in dimagi/commcare-hq Mar 26, 2015
TypeError: cannot deepcopy this pattern object
@dannyroberts
Copy link
Member

@esoergel looks like this was introduced between jsonobject 0.4 and 0.6 according to dimagi/commcare-hq#4647 (comment). If this is fixed within a week, is that fast enough?

@dannyroberts
Copy link
Member

Also according to dimagi/commcare-hq@ff67f36#commitcomment-10420066, copy.deepcopy(obj) works just fine, but copy.deepcopy(obj.foo) fails

@esoergel
Copy link
Contributor

@dannyroberts I need to do a bit more digging to figure the rest of the issue out, but I'm hoping to be able to circumvent the issue altogether, in which case the timing is less critical.

@trentgerman
Copy link

Any progress on this one?

@dannyroberts
Copy link
Member

Looks from the conversation history that we dropped it without a timeline to complete. As a workaround, Obj.wrap(obj.to_json()) is conceptually equivalent, although I realize you may not have access to the code that makes the call to deepcopy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants