models: Shortcut case where copy didn't change anything

We no longer copy in this case and will just give you the same instance back.
This commit is contained in:
Thomas Adamcik 2015-04-08 00:34:02 +02:00
parent 0fee1b4b11
commit 86481b1d50
2 changed files with 3 additions and 1 deletions

View File

@ -224,6 +224,8 @@ class ImmutableObject(object):
:type values: dict
:rtype: new instance of the model being copied
"""
if not values:
return self
other = copy.copy(self)
for key, value in values.items():
if key not in self._fields:

View File

@ -12,7 +12,7 @@ class GenericCopyTest(unittest.TestCase):
def compare(self, orig, other):
self.assertEqual(orig, other)
self.assertNotEqual(id(orig), id(other))
self.assertEqual(id(orig), id(other))
def test_copying_track(self):
track = Track()