From 560044748a8ff5488769f8ebfa8a353a8d0115fa Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 19 Nov 2019 09:30:31 -0500 Subject: Skip on slice assignment to self Fixed issue where when assigning a collection to itself as a slice, the mutation operation would fail as it would first erase the assigned collection inadvertently. As an assignment that does not change the contents should not generate events, the operation is now a no-op. Note that the fix only applies to Python 3; in Python 2, the ``__setitem__`` hook isn't called in this case; ``__setslice__`` is used instead which recreates the list item-by-item in all cases. Fixes: #4990 Change-Id: I08727880f70f4fe188de53a4dcd36746b62c7233 --- lib/sqlalchemy/orm/collections.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index 4b096c152..5008f5727 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -1201,6 +1201,8 @@ def _list_decorators(): stop += len(self) if step == 1: + if value is self: + return for i in range(start, stop, step): if len(self) > start: del self[start] -- cgit v1.2.1