Opened 4 years ago

Closed 4 years ago

#18175 closed Bug (fixed)

SortedDict issue when copied with copy.copy

Reported by: linovia Owned by: nobody
Component: Uncategorized Version: 1.4
Severity: Normal Keywords:
Cc: linovia Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If SortedDict is copied using the copy.copy, the data are duplicated.

>>> from django.utils.datastructures import SortedDict
>>> from copy import copy
>>> test = SortedDict()
>>> test['a']=1
>>> copy(test)
{'a': 1, 'a': 1}
>>> test
{'a': 1, 'a': 1}

You'll find joined a test patch to show this issue.

Attachments (3)

failing_sorted_dict_test.diff (622 bytes) - added by linovia 4 years ago.
Failing test case
sorted_dict_copy.diff (1.1 KB) - added by linovia 4 years ago.
sorted_dict_copy_2.diff (1.2 KB) - added by linovia 4 years ago.
Test & patch with a comment

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by linovia

Failing test case

Changed 4 years ago by linovia

Attachment: sorted_dict_copy.diff added

comment:1 Changed 4 years ago by linovia

Cc: linovia added
Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Here's the patch.

comment:2 Changed 4 years ago by Anssi Kääriäinen

Can you explain what is going wrong currently? Why that __copy__ method is needed? Preferably in a comment included in the patch.

Changed 4 years ago by linovia

Attachment: sorted_dict_copy_2.diff added

Test & patch with a comment

comment:3 Changed 4 years ago by Anssi Kääriäinen

Resolution: fixed
Status: newclosed
Triage Stage: UnreviewedAccepted

Fixed in commit 4b11762f7d7aed2f4f36c4158326c0a4332038f9

I did some small changes to the patch. I still don't understand why the behavior was broken before.

Thanks for the report & patch!

Note: See TracTickets for help on using tickets.
Back to Top