From b28b87958adb0f9fcf8e1d54712d5bb8606d0656 Mon Sep 17 00:00:00 2001 From: Alexey Kartashov Date: Fri, 1 Dec 2023 15:52:32 +0100 Subject: [PATCH] cqlengine: Remove deepcopy on UserType deserialization This change makes it so newly instanced UserType during deserialization isn't immediately copied by deepcopy, which could cause huge slowdown if that UserType contains a lot of data or nested UserTypes, in which case the deepcopy calls would cascade as each to_python call would eventually clone parts of source object. As there isn't a lot of information on why this deepcopy is here in the first place this change could potentially break something. Running integration tests against this commit does not produce regressions, so this call looks safe to remove, but I'm leaving this warning here for the future reference. Issue: scylladb/python-driver#152 --- cassandra/cqlengine/columns.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cassandra/cqlengine/columns.py b/cassandra/cqlengine/columns.py index 7c20ec6642..4adb88476b 100644 --- a/cassandra/cqlengine/columns.py +++ b/cassandra/cqlengine/columns.py @@ -1037,12 +1037,11 @@ def to_python(self, value): if value is None: return - copied_value = deepcopy(value) for name, field in self.user_type._fields.items(): - if copied_value[name] is not None or isinstance(field, BaseContainerColumn): - copied_value[name] = field.to_python(copied_value[name]) + if value[name] is not None or isinstance(field, BaseContainerColumn): + value[name] = field.to_python(value[name]) - return copied_value + return value def to_database(self, value): if value is None: