Code

Opened 2 years ago

Closed 2 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 2 years ago.
Failing test case
sorted_dict_copy.diff (1.1 KB) - added by linovia 2 years ago.
sorted_dict_copy_2.diff (1.2 KB) - added by linovia 2 years ago.
Test & patch with a comment

Download all attachments as: .zip

Change History (6)

Changed 2 years ago by linovia

Failing test case

Changed 2 years ago by linovia

comment:1 Changed 2 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 2 years ago by akaariai

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

Changed 2 years ago by linovia

Test & patch with a comment

comment:3 Changed 2 years ago by akaariai

  • Resolution set to fixed
  • Status changed from new to closed
  • Triage Stage changed from Unreviewed to Accepted

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!

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.