incorrect logic in collection setitem for slice

Issue #2807 resolved
Mike Bayer repo owner created an issue
diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py
index f8f4b95..54a79f7 100644
--- a/lib/sqlalchemy/orm/collections.py
+++ b/lib/sqlalchemy/orm/collections.py
@@ -1075,7 +1075,7 @@ def _list_decorators():
                 start = index.start or 0
                 if start < 0:
                     start += len(self)
-                stop = index.stop or len(self)
+                stop = index.stop if index.stop is not None else len(self)
                 if stop < 0:
                     stop += len(self)

current test case, only occurs on py3k. for some reason py2k isn't taking us there (maybe the zeroes?):

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)
    bs = relationship("B")


class B(Base):
    __tablename__ = 'b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('a.id'))


a1 = A()
b1, b2 = B(), B()
a1.bs = [b2](b2)
a1.bs[0:0](0:0) = [b1](b1)

assert a1.bs == [b2](b1,)

}}}

Comments (3)

  1. Log in to comment